简体   繁体   English

远程true无法在rails2.3.8中的表单中工作

[英]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_forform_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 仔细检查一下

  1. the jQuery library is linked from the page and make sure the link works. jQuery库是从页面链接的,并确保该链接有效。 Sometimes it's mispelled. 有时拼写错误。 Open the source and check it. 打开源并进行检查。
  2. the rails.js file is linked from the page and the link works. 从页面链接了rails.js文件,该链接有效。 Same as above. 同上。
  3. 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.

相关问题 Rails2.3.8 Resque.enqueue不会将作业转发到后台 - Rails2.3.8 Resque.enqueue doesn't forward the job to background Rails2.3.8 上的 Ruby:如何使用开发环境运行测试? - Ruby on Rails2.3.8: How do I run a test using the dev environment? Rails 3:Form_tag + remote:即使使用正确的JS也无法正常工作吗? - Rails 3: Form_tag + remote: true not working even with proper JS? 在Rails 4中发送带有远程true的表单 - Sending a form with remote true in Rails 4 验证是否存在无法在Rails 2.3.8中工作的情况 - Validates presence of not working in Rails 2.3.8 Rails 3表单远程不起作用 - Rails 3 Form Remote Not Working (MacOSx)较早版本的Rails2.3.8,我安装了Rails3.2.0,但仍无法访问新版本的Rails。 请帮我解决 - (MacOSx) Earlier version Rails2.3.8, i installed Rails3.2.0 but i still not able to access new version of Rails. Please help me fix it rails 5,remote:true表示空数据 - rails 5, remote: true form empty data Rails-带:remote =&gt; true和false的form_tag - Rails - form_tag with :remote => true and false Ruby on Rails2.3.8:单元测试:Rails / Ruby已设置为在每次测试之前运行。 在所有测试之前运行的方法呢? - Ruby on Rails2.3.8: Unit Testing: Rails/Ruby has setup to run before each test. What about a method that runs before all tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM