I have a list of names in a drop-down and when one of those names it is
picked I want my form to update a div of those selected names but to
also update the drop-down so that name no longer appears in that list,
which means I need to update two divs. I have this working in the sense
that the two seperate divs do get updated via a render :update do
page>.....
##Controller code
render :update do |page|
page.replace_html 'saved_travel_arrangers_div', :partial =>
'show_my_managers'
page.replace_html 'travel_managers_list', :partial =>
'list_managers_dropdown'
end
The problem is that 'saved_travel_arrangers_div' gets filled with, well,
to be honest, a bunch of shit! For example,
Now, the above code is in a partial which is wrraped in a div so I can
change it:
<div id = "travel_managers_list">.....</div>
And everything seems to work the way I want - changing the two divs -
but I get all this extra junk displayed in the page.
-S
I can't be 100% sure... but it seems like you are maybe updating your
the div twice.
Once in the controller:
page.replace_html 'saved_travel_arrangers_div', :partial =>
'show_my_managers'
and once in the view:
{:onchange => remote_function( :update => 'saved_travel_arrangers_div',
:url =>
{:action => 'saved_travel_arrangers', :id => @user.id}, :with =>
"'select=' + escape(value)" )}
So, I would suggest dropping the controller update and instead make it
just render the partial:
respond_to do |format|
format.js { render :partial => 'show_my_managers'}
end
just render the partial:
respond_to do |format|
format.js { render :partial => 'show_my_managers'}
end
I might be off base, sorry if I am.
I actually like that solution, I didn't know that you could do that. The
issue now is that I need to replace the HTML in the div I am updating
with new HTML. Is there a way to replace the existing HTML in the div
this way? Thanks,
just render the partial:
respond_to do |format|
format.js { render :partial => 'show_my_managers'}
end
I might be off base, sorry if I am.
I actually like that solution, I didn't know that you could do that. The
issue now is that I need to replace the HTML in the div I am updating
with new HTML. Is there a way to replace the existing HTML in the div
this way? Thanks,
-S
I'll use a concise text_field_tag method to explain how to update the
div (I am assuming the div you want to update is called
"saved_travel_arrangers_div".
I'll use a concise text_field_tag method to explain how to update the
div (I am assuming the div you want to update is called
"saved_travel_arrangers_div".
# Controller
def saved_travel_arrangers
respond_to do |format|
format.js {render :text => "#{params[:select]}"}
end
end
# JS Includes
<%= javascript_include_tag :defaults %>
Basically you are specifying the div you want to update with the :update
option. Does that make sense?
I got it to work. The issue that I was having was that in one of my
partials I had a table formated wrong - basically I had row and colums
tags but not within table tags. This was allowing bizarre formating to
occur. I did end up using the method found above, but I am still curious
as to why the render :update didn't work? I am using similar code on
another page and it works fine. But this code:
render :update do |page|
page.replace_html 'saved_travel_arrangers_div', :partial
=>'show_my_managers'
page.replace_html 'travel_managers_list', :partial
=>'list_managers_dropdown'
end
renders some try catch code along with all the other wierd formatting I
described on the initial post to this discussion. The reason why I
initially wanted to do it using the render :update is because I needed
to update two div within one action. Anyone have any ideas? Thanks,
I got it to work. The issue that I was having was that in one of my
partials I had a table formated wrong - basically I had row and colums
tags but not within table tags. This was allowing bizarre formating to
occur. I did end up using the method found above, but I am still
curious
as to why the render :update didn't work? I am using similar code on
another page and it works fine. But this code:
render :update do |page|
page.replace_html 'saved_travel_arrangers_div', :partial
=>'show_my_managers'
page.replace_html 'travel_managers_list', :partial
=>'list_managers_dropdown'
end
renders some try catch code along with all the other wierd
formatting I
described on the initial post to this discussion. The reason why I
initially wanted to do it using the render :update is because I needed
to update two div within one action. Anyone have any ideas? Thanks,
That's because you are passing :update to remote_function. Stop doing
that and you'll be ok.
the :update option means 'stuff the response body into this page
element' whereas you want the response to be executed.