2

When I try to update and save ActiveResource I am getting following error.

on console

> m = Machine.first
 => #<Machine:0xb07a0d4 @attributes={"created_at"=>"2013-04-22T09:13:56Z", "id"=>1, "name"=>"laptop", "updated_at"=>"2013-04-22T09:13:56Z"}, @prefix_options={}, @persisted=true>

> m.name = 'mouse'
 => "mouse"

> m.save
ActiveResource::ServerError: Failed.  Response code = 500.  Response message = Internal Server Error

on server

ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: created_at, id, updated_at):
  app/controllers/machines_controller.rb:62:in `block in update'
  app/controllers/machines_controller.rb:61:in `update'

Here is ActiveResource model

class Machine < ActiveResource::Base
  self.site = 'http://localhost:3000'
end

Here is ActiveRecord model

class Machine < ActiveRecord::Base
  attr_accessible :name
end
4

0 回答 0