开发者

RoR: Link_to_remote - updating text field

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=>'s开发者_StackOverflow中文版treet_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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜