Forms, view & AJAX best practice help

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?

James W. 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?

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

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