简体   繁体   English

Rails 3.2.3-Javascript-application.js-link_to_remove_fields

[英]rails 3.2.3 - javascript - application.js - link_to_remove_fields

I am trying to implement the idea of link_to_remove_fields from Ryan's "railscasts episode-197 ". 我正在尝试从Ryan的“ railscasts Episode-197”中实现link_to_remove_fields的想法。

I seem to be having problems with the javascript file " 我的javascript文件似乎有问题“

My application.html.erb file includes javascript: <%= javascript_include_tag "application" %> 我的application.html.erb文件包含javascript:<%= javascript_include_tag“应用程序”%>

And I add the following function to the application.js file: 然后将以下函数添加到application.js文件:

function remove_fields(link) {
 $(link).previous("input[type=hidden]").value = "1";
 $(link).up(".fields").hide();
}

And I have the following code in the application_helper.rb file: 我在application_helper.rb文件中有以下代码:

def link_to_remove_fields(name, f)
  f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
end

And in my _form I have: 在我的_form中,我有:

<%= f.label :entry, "Descriptions" %><br />
<%= f.text_area :entry, :rows => 3 %>
<%= link_to_remove_fields "remove", f %><br />
<%= f.hidden_field :user_id, :value => current_user.id %>

When i kick off the rails server and navigate to the page i am working on, the "remove" links appear, but nothing happens when I click on it. 当我启动Rails服务器并导航到我正在处理的页面时,将显示“删除”链接,但是单击它不会发生任何反应。

So I have a hunch that the javascript code is not being called? 所以我有一个预感,就是没有调用javascript代码?

Any ideas? 有任何想法吗?

Thanks guys! 多谢你们!

Adam 亚当

Can you please be sure, that your js code is not triggered? 您能否确定未触发您的js代码? Please take a look with firebug or chromes build in debugtool 请看看在debugtool中构建的Firebug或Chromes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM