Why are you doing this in javascript when you can do this beautifully
in your controller? Create the appropriate validations in your model
and then in your controller check whether saving is possible. If it
is, save it and redirect or whatever you want it to do. If not, catch
the error and show it.
On 22 aug, 09:17, Wap Addon <[email protected]> wrote:
> I am using form for here is my code
> new.html.erb
>
> <h1>New animal</h1>
>
> <% form_for(@animal) do |f| %>
>   <%= f.error_messages %>
>
>   <p>
>     <%= f.label :name %><br />
>     <%= f.text_field :name %>
>   </p>
>   <p>
>     <%= f.label :desc %><br />
>     <%= f.text_field :desc %>
>   </p>
>   <p>
>     <%= f.submit 'Create', :onClick => 'new_animal();' %>
>   </p>
>
> <% end %>
> <%= link_to 'Back', animals_path %>
>
> main.js
>
> function new_animal(){
> alert('animal');
>   if(document.getElementById('animal_name').value=="")
>       {
>           alert("Enter name...");
>           document.getElementById('animal_name').focus();
>           return false;
>       }
>   if(document.getElementById('animal_desc').value=="")
>       {
>           alert("Enter animal description ...");
>           document.getElementById('animal_desc').focus();
>           return false;
>       }
>
> }
>
> i got message that animal then i preesed ok form redirt to index page
> and insert record in db.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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