Skip to content

Instantly share code, notes, and snippets.

@armandofox
Created February 16, 2016 01:15
Show Gist options
  • Save armandofox/60a85a64799ea238c045 to your computer and use it in GitHub Desktop.
Save armandofox/60a85a64799ea238c045 to your computer and use it in GitHub Desktop.
edit_update.rb
# in movies_controller.rb
def edit
@movie = Movie.find params[:id]
end
def update
@movie = Movie.find params[:id]
@movie.update_attributes!(params[:movie])
flash[:notice] = "#{@movie.title} was successfully updated."
redirect_to movie_path(@movie)
end
@sa7mon
Copy link

sa7mon commented Feb 16, 2018

To avoid ForbiddenAttributesError:

def update
   @movie = Movie.find params[:id]
   permitted = params[:movie].permit(:title,:rating,:release_date)
   @movie.update_attributes!(permitted)
    
   flash[:notice] = "#{@movie.title} was successfully updated."
   redirect_to movie_path(@movie)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment