Advertisement
saasbook

controller_with_validation.rb

Jan 10th, 2012
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.59 KB | None | 0 0
  1. # replaces the create method in controller:
  2. def create
  3.   @movie = Movie.new(params[:movie])
  4.   if @movie.save
  5.     flash[:notice] = "#{@movie.title} was successfully created."
  6.     redirect_to movies_path
  7.   else
  8.     redirect_to new_movie_path # note, 'new' template can access @movie's field values!
  9.   end
  10. end
  11.  
  12. # replaces the update method in controller:
  13. def update
  14.   @movie = Movie.find params[:id]
  15.   if @movie.update_attributes(params[:movie])
  16.     flash[:notice] = "#{@movie.title} was successfully updated."
  17.     redirect_to movie_path(@movie)
  18.   else
  19.     redirect_to edit_movie_path(@movie)
  20.   end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement