views:

66

answers:

1

I'm trying to use rails to change a textfield's value with a link_to_remote

<%= link_to_remote address.street, :url => {:controller => 'incidents', :action=>'street_selected', :update => "street.value" } %>

Street is the id of the textfield

my controller function renders text, but the textfield value isn't changed. How do i get this to work?

A: 

You could either remove and replace the text field or just update the value. Updating the value itself probably much simpler. The following assumes you haven't switched out Prototype for jQuery or another JS toolset.

In the view:

<%= link_to_remote address.street, :url => {:controller => 'incidents', 
  :action=>'street_selected'} %>

In the controller

def street_selected
  ...
    code that gets new value
  ...
  respond_to |format| do
    format.js { render :update do |page|
       page <<"$('textfield').value = new_value
    end
  }
end

P.S. You might want to pass some parameters in that remote link to allow for dynamic processing. Otherwise there's no point in doing this with AJAX.

EmFi