How to update multiple columns in Ruby on Rails 3?
You can use update_all
as follows:
User.where(:id => user.id).update_all({:field1 => true, :field2 => true})
This will generate the following update statement (mysql):UPDATE users SET field1 = 1, field2 = 1 WHERE users.id = <whatever>
Callbacks and validations will not be run. update_column method for multiple attributes
You can use update_columns(attr1: val1, attr2: val2, attr3: val3)
as documented here. You just need to pass in the key-value pairs, not an actual hash object.
Rails: Update model attribute without invoking callbacks
Rails 3.1 introduced update_column
, which is the same as update_attribute
, but without triggering validations or callbacks:
http://apidock.com/rails/ActiveRecord/Persistence/update_column
update_columns update a string but it's nil when fetching on rails
You have some method defined on Document
class (or included module) that is overriding the default attribute accessor.
To find out which, write this in console:
Document.find(14).method(:path).source_location
In any case you can access directly the attribute withDocument.find(14)['path']
Rails 3: Database column won't update through active record
remove :role
from this line attr_accessor :password, :password_confirmation, :role
Related Topics
Ruby/Rails Audio Conversion Plugins
Automatically Adding Proxy to All Http Connections in Ruby
Watir Changing Mozilla Firefox Preferences
Parsing a CSV File Using Different Encodings and Libraries
Using Multiple Yields to Insert Content
Algorithm to Render a Horizontal Binary-Ish Tree in Text/Ascii Form
How to Pick The Method to Call When There Is Mixin Method Name Conflict
Strong Parameters with Nested Hash
I Need to Go from HTML to Markdown, Any Suggestion
How to Reverse a Linked List in Ruby
How to Get Nokogiri to Parse and Return an Xml Document
Get Route for Base Class of Sti Class in Rails
Pod Install in Xcode Bots Trigger
Why The Unit Test Frameworks in Fortran Rely on Ruby Instead of Fortran Itself
Securely Display an Image Uploaded with Paperclip Gem
Convert Durations in Ruby - Hh:Mm:Ss.Sss to Milliseconds and Vice Versa
Should I Move My Custom Methods to Model from Controller
Why Does Including This Module Not Override a Dynamically-Generated Method