Rails update attributes not updating
Just like above, this method does not yet change the attribute in the database.
def update @entry = Entry.find(params[:id]) puts "received HTTP request to update old entry:# with" puts "new parameters: #" if @entry.update_attributes(params[:entry]) puts"Update was successful" @entry2 = Entry.find(params[:id]) puts "Here is the new value #" end end As you can see the old record was not really updated.
If guard_protected_attributes is true (the default), then sensitive attributes can be protected from this form of mass-assignment by using the attr_protected macro.
apidock.com/rails/Active Record/Persistence/update_column Source: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_Another cheat sheet: in case of .attributes = val, if your model has_one and accepts_nested_attributes_for another model, passing that_model_attributes (without id) will delete the existing has_one model, even if you didn't persist (e.g. But assign_attributes doesn't behave like that. Source: Record/attributes=(new_attributes, guard_protected_attributes = true) Allows you to set all the attributes at once by passing in a hash with keys matching the attribute names (which again matches the column names).
raises an exception to inform that an error has occurred.Can you post code of the form you used to update entry?It's just a hunch but your form is not sending the params the correct way, where your entry attributes should be wrapped up in a entry attribute. Your parameters regarding entry are wrapped up and attached to the attribute entry. This is mostly useful in relation to single-table inheritance structures where you want a subclass to appear as the superclass.
This can be used along with record identification in Action Pack to allow, say, to render that instance using the companies/company partial instead of clients/client.
If it defaults to true - rails might not bother adding it to the set of attributes.