Don*_*ham 10 javascript ruby-on-rails link-to
在我的index.html.erb文件中,我试图显示我的对象的标题("列表")和正常的"显示","编辑"和"销毁"链接和/或按钮.使用:method =>:delete and:confirm =>"你确定吗?",link_to或button_to都不会显示javascript确认框.这是我的index.html.erb:
<h2><a href="#" onclick="alert('Hello world!'); return false;">Click Here for a Javascript test</a></h2>
<table>
<tr>
<th>List Title</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @listings.each do |listing| %>
<tr>
<td><%= listing.title %></td>
<td><%= button_to 'Show', listing %></td>
<td><%= button_to 'Edit', edit_listing_path(listing) %></td>
<td><%= button_to( 'Destroy', listing,
:confirm => 'Are you sure?', :method => :delete)%> </td>
<td><%= link_to "Destroy", listing, :confirm => "Are you sure?", :method => :delete %> </td>
</tr>
<% end %>
</table>
Run Code Online (Sandbox Code Playgroud)
列表顶部的"Hello World"JS确认链接工作正常,因此我非常确定不引人注目的javascript对我的应用程序运行正常.(我还确认我有必要的--javascript_include_tag:defaults和csrf_meta_tag在我的应用程序模板中.)Rails文档确认支持我正在使用的参数(url,:confirm,:method).但是,button_to或link_to都不会生成由以下指示的JS警报:confirm.另外一点奇怪,使用完全相同的参数,button_to将删除记录而link_to则不会.
任何有关如何调查以解决此问题的建议将不胜感激.
谢谢!
| 归档时间: |
|
| 查看次数: |
12000 次 |
| 最近记录: |