Is there a better way to write the find_messages_by_slug_or_404 method?

Posted by J. Pablo Fernández on Stack Overflow See other posts from Stack Overflow or by J. Pablo Fernández
Published on 2010-03-20T21:04:56Z Indexed on 2010/03/20 21:11 UTC
Read the original article Hit count: 145

Filed under:
|
|

In my messages_controller I have the following private method:

def find_message_or_404(slug)
  message = user.messages.find_by_slug(slug)
  if message.nil?
    raise Error404
  end
  message
end

I find it not elegant and not very Rubist. Is there a way to improve it?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails