开发者

haml and no javascript? (rails: form_remote_tag and :with parameter)

开发者 https://www.devze.com 2022-12-20 17:09 出处:网络
i am trying to call a remote method to update page content via ajax/js. either i am too tired already or haml is not parsing the following code correctly to send the value of the query f开发者_如何学编

i am trying to call a remote method to update page content via ajax/js. either i am too tired already or haml is not parsing the following code correctly to send the value of the query f开发者_如何学编程ield via prototype. any ideas?

- form_remote_tag(:url => {:controller => "search", :action => "line"},:with => "'query=' + $('query').value" ) do
  %input{:type => 'text', :id => 'query'}
  %input{:type => 'submit', :value => 'Search'}

thanks a lot!

t


Have you tried a

= form_remote_tag

instead of

- form_remote_tag

I'm new to HAML myself but I was under the impression that you'll need the form tag to be actually generated not just executed...


Try passing the :with as part of the options hash.

- form_remote_tag({ :url => {:controller => "search", :action => "line"}, :with => "'query=' + $('query').value" }) do

If that doesn't work, debug the problem: Look at the generated html. Is the text field with id query the only element in the page with that id? Is the js code correct? Use the Firebug console to ensure $('query').value returns whatever you've entered into the text field.

Still stuck? Add your generated html into your question so we can better help.

EDIT: Your query input tag does not have a name attribute. Without a name, the javascript helper code skips that field when serializing the form fields...also, you do not need the :with code.

%input{:type => 'text', :id => 'query', :name => 'query'}
0

精彩评论

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