I have some custom methods defined in my task model. I’m sending them into my backbone application like so:
Planner.initialize({ tasks: #{raw @tasks.to_json(:methods => [:timeframe, :timeframe_title, :timeframe_months]) } });
However, after I added that, ActiveRecord thinks it’s a field in the database, and I’m getting the following error in the console:
Completed 500 Internal Server Error in 4ms
ActiveRecord::UnknownAttributeError (unknown attribute: timeframe):
app/controllers/tasks_controller.rb:118:in `block in update'
app/controllers/tasks_controller.rb:117:in `update'
Thanks to Chad Pytel at ThoughtBot, I found that I had to remove these three methods from my attr_accessible line in my rails model.
Highly recommend the book “Backbone.js on Rails” by Thoughtbot, which comes with chat support for problems like these.