What is the difference between User.first and User.first! in Ruby on Rails?
I see the example in the Ruby Guide but there is no explanation between why it’s different. As far as I know, ! is used to represent that the method is changing the variable.
*User represents a table.
I didn’t know there was a
first!finder method in ActiveRecord. Thanks to your question, now I know 🙂first!is the same asfirstexcept that it raises ActiveRecord::RecordNotFound if no record is found.More details here : http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-first-21