Forum: Ruby on Rails Forms, view & AJAX best practice help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B0be4bfef5a22697a0f44f4fe295aaef?d=identicon&s=25 James Whittaker (aftershock)
on 2006-04-04 16:40
What i'm trying to get working is I have a controller called
"permissions" and a view "permissions.rhtml". This view has a hidden div
that contains a form for adding new roles. Its just a single textfield.
Also on the page I have a dropdown list of roles and then underneath
that a div that contains a list of permissions for the role selected in
the dropdown. I have a link that when clicked makes the hidden form div
visible.

What I would like is for the form to submit via AJAX to a new_role
controller method. Any errors would be highlighted in my
"error_messages_for 'role'" call at the top of the permissions.rhtml
file. When it has submitted correctly the dropdown list would be updated
with the new selection.

What I have got so far is that the page wants to show a "new_form" page?
B0be4bfef5a22697a0f44f4fe295aaef?d=identicon&s=25 James Whittaker (aftershock)
on 2006-04-04 17:29
James Whittaker wrote:
> What i'm trying to get working is I have a controller called
> "permissions" and a view "permissions.rhtml". This view has a hidden div
> that contains a form for adding new roles. Its just a single textfield.
> Also on the page I have a dropdown list of roles and then underneath
> that a div that contains a list of permissions for the role selected in
> the dropdown. I have a link that when clicked makes the hidden form div
> visible.
>
> What I would like is for the form to submit via AJAX to a new_role
> controller method. Any errors would be highlighted in my
> "error_messages_for 'role'" call at the top of the permissions.rhtml
> file. When it has submitted correctly the dropdown list would be updated
> with the new selection.
>
> What I have got so far is that the page wants to show a "new_form" page?

Ok I will rephrase it:

How can I get Error messages to show when using ajax form submit?
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-04-04 18:28
(Received via mailing list)
James
    > How can I get Error messages to show when using ajax form submit?

In the controller's response to the submit, you will send an html
fragment with RJS code like:
     ...
     page.replace_html "the_div_id", :partial => 'some_html_fragment'
     ...


The trick is for the html fragment to include the error displaying Rails
code :
        ...
       <%= error_messages_for 'foo' %>
       ....


Alain
525128e48ca2b4c7fb6176ea166fccfd?d=identicon&s=25 Eric G. (gotskill10)
on 2006-12-25 02:53
or you could do something like this without having to use a partial

         render :update do |page|
            page.replace_html 'address_errors', :inline=>"<%=
error_messages_for :address %>"
         end
This topic is locked and can not be replied to.