RAils named routes inside Jquery autosuggest -
i working in rails2.3.11. have javascript like
<script type="text/javascript"> $(item).autosuggest("/users/sampledata",{selecteditemprop: "name", searchobjprops: "name,login", ashtmlid: elmid,beforeretrieve: function(string){ $('#spinner').show(); return string; },retrievecomplete: function(data){ $('#spinner').hide(); return data; } }); </script>
i trying convert path "/users/sampledata" rails format sampledata_users_path.. how ??
the controller users controller , action sampledata action has
def sampledata @users = user.search(params["q"].gsub(/[^ \w]/, "").strip + "*", :limit => 8) js = [] @users.each |user| js << {:value => user.id.to_s, :name => user.name, :image => user.avatar.url(:micro), :login => user.login} end respond_to |format| format.json { render :json => js.to_json } end end
is above "javascript" in javascript file or part of erb template?
if part of erb template easy.
<script type="text/javascript"> $(item).autosuggest("<%= sampledata_users_path %>",{selecteditemprop: "name", searchobjprops: "name,login", ashtmlid: elmid,beforeretrieve: function(string){ $('#spinner').show(); return string; },retrievecomplete: function(data){ $('#spinner').hide(); return data; } }); </script>
if above not in dynamically generated file, may want @ plugin reads routes file , generates javascripts constants use in js. think called "less_routes" or something.
Comments
Post a Comment