Hi,

I have been reading a lot about this, but I do not manage to do a nice
validation. I already managed to save data to the database, to
validate a field, to display a "Everything went well" message. I can
also display an error message, but the view does not end up properly.

This is the form:

<% remote_form_for(product) do |f| %>
    <%= f.error_messages %>
          <p>
                  <%= f.label :title  %><br />
                  <%= f.text_field :title %>
          </p>
          <p>
                  <%= f.label :body  %><br />
                  <%= f.text_area :body %>
          </p>
          <p>
            <%= f.submit "Update" %> รณ
         </p>
  <% end %>

This is the controller:

def update
    @product = Product.find(params[:id])
    respond_to do |format|
      if @product.update_attributes(params[:product])
        flash[:notice] = 'OK!'
        format.html { redirect_to(@product) }
        format.js
      else
        flash.now[:notice] = 'Error!!'
        format.html { render :action => "show" }
        format.xml { render :xml => @product.errors,  :status
=> :unprocessable_entity }
        format.js
      end
    end
  end

The model:

class Product < ActiveRecord::Base
  validates_presence_of :title
end

And the RJS template:

page.replace_html :description, :partial => "product", :object =>
@product
page.replace_html :notice, flash[:notice]
page.visual_effect (:fade, "notice", :duration => 2)
flash.discard

But I thing there is a better way to validate forms.

Does any one have an example about validating, and displaying
customized messages.

Br,

Isaac

--~--~---------~--~----~------------~-------~--~----~
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