Hi All

I have a problem with passing Validation error messages from my model
'Visitor' to my view 'index.html.erb'.
When I pass an invalid surname from the form on my view, I correctly
get an invalid response on my error page when I use the render :action
=> 'error command in my controller.

However I want this error message to appear on my index page and I
want the form to be redirected to this page.

My question is how can I pass the error failure from my model to the
view, using a redirect_to?

Many thanks, and Happy New Year!

Ben...


index_controller.rb
=============

  def create
    @visitor = Visitor.new(params[:visitor])

    respond_to do |format|
      if @visitor.save
        format.html { redirect_to :action => 'index' }
      else
        # format.html  { render :action => 'error' }
        # format.html  { render :controller => 'index', :action =>
'index' }
        format.html { redirect_to :action => 'index' }
      end
    end
  end


index.html.erb
==========
      <p class="form_failure clear"><%= error_messages_for 'visitor'
%></p>


visitor.rb
======

class Visitor < ActiveRecord::Base

  validates_presence_of :surname, :message => 'is invalid!'

end


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to