render :update

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,

try { Element.update("saved_travel_arrangers_div", "
\n\t\n\t\t\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t\n\t\n\t\t\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t
\n\t\t\t
\n\t\t
\n\t\t\n\t\n

Why is it putting this as output and how do I get rid of it? Thanks in
advance for the help,

-S

How are you including your javascript?

Lake

Lake Denman wrote:

How are you including your javascript?

Lake

The action get intiated by the onchange of a dropdown, so I have:

<%= select( "managersplususers", "travel_arranger_id",
  User.find( :all, :conditions => ['role = ? and primary_account_id = ?
and id
  NOT IN( SELECT travel_arranger_id FROM Managersplususers WHERE user_id
= \''
  + @user.id.to_s + '\')', 'Travel Manager',
  @user.primary_account_id] ).collect {|h| [h.first + " "
  + h.last, h.id]}, { :include_blank => true }, {:onchange =>
  remote_function( :update => 'saved_travel_arrangers_div', :url =>
{:action =>
  'saved_travel_arrangers', :id => @user.id},
  :with => "'select=' + escape(value)" )}) %>

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

Shandy Nantz wrote:

Lake Denman wrote:

How are you including your javascript?

Lake

The action get intiated by the onchange of a dropdown, so I have:

<%= select( "managersplususers", "travel_arranger_id",
  User.find( :all, :conditions => ['role = ? and primary_account_id = ?
and id
  NOT IN( SELECT travel_arranger_id FROM Managersplususers WHERE user_id
= \''
  + @user.id.to_s + '\')', 'Travel Manager',
  @user.primary_account_id] ).collect {|h| [h.first + " "
  + h.last, h.id]}, { :include_blank => true }, {:onchange =>
  remote_function( :update => 'saved_travel_arrangers_div', :url =>
{:action =>
  'saved_travel_arrangers', :id => @user.id},
  :with => "'select=' + escape(value)" )}) %>

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

I might be off base, sorry if I am.

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

Shandy Nantz wrote:

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".

# View
<%= text_field_tag "Hallo!", "#", :onclick =>
remote_function(:update=>'saved_travel_arrangers_div', :url => {:action
=>'saved_travel_arrangers'}, :with =>
"'select=' + escape(value)") %>

# 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'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".

# View
<%= text_field_tag "Hallo!", "#", :onclick =>
remote_function(:update=>'saved_travel_arrangers_div', :url => {:action
=>'saved_travel_arrangers'}, :with =>
"'select=' + escape(value)") %>

# 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,

-S

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.

Fred