Advertisement
saasbook

controller_with_validation.rb

Feb 20th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.61 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.     render 'new' # 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.     render 'edit' # note, 'edit' template can access @movie's field values!
  20.   end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement