Rendering an action with :notice that depends on a URL param

ruby-on-rails, ruby-on-rails-3

Solution

change this `render 'approval', :notice => "Saved!"` to

flash[:notice] = "Saved!"
redirect_to :back

Problem

I have an action 'approval' that renders a view which displays some content from a Model (class). Within the view I have a link_to that calls `accept` with a URL parameter (:id). After the `accept` action completes (sets approve to true) I would like to render `approval` again with a message ("Saved!"). However, unlike a static login page, the approval action requires a param the first time it is called. The second time it is rendered, an runtime error occurs (obviously). What is the best way to call `approval` with the flash notice? ``` def approval @c = Class.find(params[:id]) end def accept @c = Class.find(params[:id]) @c.approve = true @c.save render 'approval', :notice => "Saved!" end ```

Original source