Ruby on Rails
Monday, February 3, 2014
On Saturday, 1 February 2014 20:15:38 UTC-5, Bizt wrote:
Consider, though, that if for whatever reason an invalid id is passed
in, @account will be nil and so @account.transactions will give you
a NoMethod error.
What do you want to happen at that point?
Good point. Thanks, I'll put some checking to see if account is valid or not and handle it accordingly.
One quick way to do that is to use plain `find` instead of `find_by_id`, thus:
@account = current_user.accounts.find(params[:account])
If a user attempts to request an account that doesn't belong to them, this will raise ActiveRecord::RecordNotFound. The default Rails rescue_from will translate that into an HTTP 404 Not Found response.
--Matt Jones
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/68205ea7-b870-4569-8c82-2d3989c11936%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment