Created
October 26, 2011 13:57
-
-
Save unixmonkey/1316430 to your computer and use it in GitHub Desktop.
Redirect and still show error messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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