Example scenario: I'm on my mac's Terminal inside the Rails console and have just entered the following database record with a misspelling in one of the fields:
irb(main):019:0> Meme.create(:category => 'funny', :title => 'Balloon frihgtens cat')
Q: Using the Rails console, how can I fix that record to have the correct spelling of "frihgtens"?
Rails Delete operation using delete method Unlike the destroy method, with delete, you can remove a record directly from the database. Any dependencies to other records in the model are not taken into account. The method delete only deletes that one row in the database and nothing else.
Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.
Step 1. Find the record.
Step 2. Edit the record.
Assuming title
is unique, the following should work:
> m = Meme.where(:title => 'Balloon frihgtens cat').first
> m.title = 'Balloon frightens cat'
> m.save
Read up http://guides.rubyonrails.org/active_record_querying.html to learn more about using active record.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With