Advertisement
saasbook

nil_object.rb

Aug 15th, 2013
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.28 KB | None | 0 0
  1. # in controller action:
  2. def show
  3.   @movie = Movie.find_by_id(params[:id]) # what if this movie not in DB?
  4.   # BUG: we should check @movie for validity here!
  5. end
  6.  
  7. -# ...later, in the Haml view:
  8.  
  9. %h1= @movie.title
  10. -# will give "undefined method 'title' for nil:NilClass" if @movie is nil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement