dynamic link_to_remote in rails with jquery

Posted by Claus Lensbøl on Stack Overflow See other posts from Stack Overflow or by Claus Lensbøl
Published on 2010-06-15T11:40:28Z Indexed on 2010/06/15 11:42 UTC
Read the original article Hit count: 458

Filed under:
|
|
|

Hi

I'm trying to pass a string with a link_to_remote call as the :id, and the string should be collected from an input field with and id of "movie_title".

<div id="search_list">Nothing here yet</div>
<br />

<% semantic_form_for @movie do |f| %>
    <% f.inputs do -%>
        <%= f.input :title, :class => "movie_title" %> <%= link_to_remote( 'Search...', { :url => { :action => :imdb_search, :id => "'+$('\#movie_title').value+'" } }, { :title => "Search for this movie", :class => "imdb_search" } ) -%>
        [...removed text that does not matter...]
    <% end -%>
    <%= f.buttons %>
<% end %>

I keep getting an javascript error, and if I remove the # from the jquery in the link, it returns "Undefined".

The link I get is:

<a class="imdb_search" href="#" onclick="jQuery.ajax({data:'authenticity_token=' + encodeURIComponent('yHPHYTZsPTQLi9JYSauUYcoie/pqPPk2uHBTN0PzNsQ='), dataType:'script', type:'post', url:'/movies/imdb_search/'+$('%23movie_title').value+''}); return false;" title="Search for this movie">Search...</a>

So I want the link updated with the contents of movie_title. How do I do that?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about ruby-on-rails