Skip to content

Instantly share code, notes, and snippets.

@unixmonkey
Created October 26, 2011 13:57
Show Gist options
  • Select an option

  • Save unixmonkey/1316430 to your computer and use it in GitHub Desktop.

Select an option

Save unixmonkey/1316430 to your computer and use it in GitHub Desktop.
Redirect and still show error messages
# app/controllers/ballots_controller.rb
def create
@ballot = Ballot.new(params[:ballot])
if @ballot.save
redirect_to @ballot, :notice => 'Successful'
else
session[:error_messages] = @ballot.errors.full_messages
redirect_to edit_ballot_path(@ballot, :params => params), :notice => 'Ruh Roh!'
end
end
# /app/views/ballots/edit.html.erb
<% if session[:error_messages] %>
<ul class="validation_errors">
<% session[:error_messages].each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment