Michael has given one example. Here's my turn. When having nested routes like `/trees/42/apples`, I'm doing a `Tree.find(42)` and it raises if there's no such tree. In other case, when the object is associated to current_user, there's no need to put its id in the routes, but for symmetry I would still like to call something that conveniently raises if the record is not present.
On Wednesday, September 25, 2013 5:50:20 AM UTC+3, Xavier Noria wrote: > > On Tue, Sep 24, 2013 at 11:58 PM, Roman <[email protected] > <javascript:>>wrote: > > Hi, >> just stumbled upon a need to raise a NotFound exception when the object >> doesn't have a necessary association. So instead of writing >> `Company.find(current_user.company_id)` or `current_user.company || raise >> AR::RecordNotFound`, maybe it would be nicer to just say >> `current_user.company!`. What do you think? >> > > Do you have a real use case to share for that need? > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
