Model validation

hello guys

i am using model validation with ajax

i have new.html.erb

it is call through link__to_remote()

then press create if any validate require page will redirect to it
actual controller for ex. admins/new something like this

i want display validation message on same page in this command url can
not change in all page url remain same, if any one having idea about it
please share with me.

index.html.erb

<%= link_to_remote('New', :update => 'pravin',:url => {:action => :new})%>
---------------------- new.html.erb ----------------------

New animal

<% form_for @animal do |f|%>

Name

<%= f.text_field :name%>

Desc

<%= f.text_field :desc %>

<%= submit_tag 'Create' %>

<% end %> <%= image_tag 'rails.PNG', 'rails.png', :size => '70x70'%> <%= link_to 'Back', animals_path %>
---------------------- it is my contrller -------------------- def create @animal = Animal.new(params[:animal]) respond_to do |format| if @animal.save flash[:notice] = 'Animal was successfully created.' format.html { redirect_to(@animal) } format.xml { render :xml => @animal, :status => :created, :location => @animal } else format.html { render :action => "new" } format.xml { render :xml => @animal.errors, :status => :unprocessable_entity } end end end ---------------- model vaidation ---------------- class Animal < ActiveRecord::Base validates_presence_of :name,:desc end ------------------------ i want to show validation on same page whenever refresh page go to on main page

Wap A. wrote:

hello guys

i am using model validation with ajax

i have new.html.erb

it is call through link__to_remote()

then press create if any validate require page will redirect to it
actual controller for ex. admins/new something like this

i want display validation message on same page in this command url can
not change in all page url remain same, if any one having idea about it
please share with me.

Can you show me your code.

method in controller + html view all code.

def create
@animal = Animal.new(params[:animal])
respond_to do |format|
#INCLUDE THIS LINE

 if @animal.save
   flash[:notice] = 'Animal was successfully created.'
   format.html { redirect_to(@animal) }
   format.xml  { render :xml => @animal, :status => :created,

:location => @animal }
else
format.html { render :action => “new” }
format.xml { render :xml => @animal.errors, :status =>
:unprocessable_entity }
end
end
end

On Mon, Aug 24, 2009 at 3:34 PM, Wap A.
<[email protected]

mahesh s wrote:

Maheshror

def create

@animal = Animal.new(params[:animal])
respond_to do |format|
#INCLUDE THIS LINE
if @animal.valid?
#if @animal.save

animal.save

end

try this
ok dear but it can not save record on table this is new problem.
i think u tell me like this ?


def create
@animal = Animal.new(params[:animal])
respond_to do |format|
#if @animal.save
if @animal.valid?
flash[:notice] = ‘Animal was successfully created.’
format.html { redirect_to(@animal) }
format.xml { render :xml => @animal, :status => :created,
:location => @animal }
else
format.html { render :action => “new” }
format.xml { render :xml => @animal.errors, :status =>
:unprocessable_entity }
end
end
end

Maheshror

def create

@animal = Animal.new(params[:animal])
respond_to do |format|
#INCLUDE THIS LINE
if @animal.valid?
#if @animal.save

animal.save

end

try this

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs