[英]remote true not working in form in rails2.3.8
I am using ruby 1.8.7. 我正在使用ruby 1.8.7。 I just wrote a simple form that sends ajax request to certain action using remote true, but it isn't seem to be working! 我只是编写了一个简单的表单,该表单使用remote true将ajax请求发送到某些操作,但是它似乎不起作用!
I have included jquery1.6.3.js and rails.js. 我包括了jquery1.6.3.js和rails.js。 The form is simple and looks like this: 表单很简单,看起来像这样:
<% form_tag("/click_button", :remote => true) do %>
<%= text_field_tag "something" %>
<%= submit_tag "Add" %>
<% end %>
The click_button method just renders the js click_button方法仅呈现js
def click_button
respond_to do |format|
format.js
end
end
The problem with is that when I click the button, there is no request to be seen in the console of the firebug, instead the page is being redirected to /click_button.erb and it gives an missing error template. 问题是,当我单击按钮时,在萤火虫的控制台中没有看到任何请求,而是页面被重定向到/click_button.erb,并且它提供了一个丢失的错误模板。 Can anyone please help me with this? 谁能帮我这个忙吗?
[Edited] The generated html code is like this: [编辑]生成的html代码是这样的:
<form remote="true" method="post" action="/data_management/add_configuration_data">
<input id="something" type="text" name="something">
<input type="submit" value="Add" name="commit">
</form>
try this 尝试这个
<% form_remote_for :xyz, :url => {:controller => "controller-name", :action => "action-name"} do |f| %>
<%= text_field_tag "something" %>
<%= submit_tag "Add" %>
<% end %>
For rails 2.3.8 you have to use remote_form_for
OR form_remote_tag
instead :remote => true
对于Rails 2.3.8,您必须使用remote_form_for
或form_remote_tag
代替:remote => true
<% remote_form_for("/click_button"e) do %>
<%= text_field_tag "something" %>
<%= submit_tag "Add" %>
<% end %>
It seems that the remote handler is not attached to the form. 似乎远程处理程序未附加到窗体。 Double check that 仔细检查一下
Add the csrf_meta_tag
tags in the page in the header section 在页眉部分的页面中添加csrf_meta_tag
标签
<%= csrf_meta_tag %>
我尝试做类似remote_true的操作,但是它似乎没有用,所以我找到了一种通过javascript解决此问题的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.