简体   繁体   English

:_method =>:delete的link_to在Rails 3中不起作用

[英]link_to with :method=>:delete not working in Rails 3

I can't get my link_to helper, with :method => :delete to destroy object 我无法使用:method =>:delete破坏对象来获取我的link_to助手

My app is like this 我的应用就是这样

aplication.html.erb aplication.html.erb

    <!--<!DOCTYPE html>
    <html>
    <head>
      <title>Taskprogect</title>
      <%= stylesheet_link_tag :all %>
    <%= javascript_include_tag :defaults %>
    <%= csrf_meta_tag %>
    </head>
    <body>
    <%= yield %>
    </body>
    </html>-->
    <h1>Application layout!</h1>
    <%= yield %>

tasks_controller.rb tasks_controller.rb

      def destroy
        Task.find(params[:id]).destroy
        flash[:success] = "Task destroyed."
        redirect_to tasks_path
      end

index.html.erb index.html.erb

  <%= link_to "delete", task, :method => :delete, :confirm => "You sure?",
  :title => "Delete #{task.name}" %>

routes.rb 的routes.rb

    Taskprogect::Application.routes.draw do

      resources :projects
      resources :tasks

    end

And link_to doesn't work, in previous app that worked, maybe I have done something bad in routes.rb? 而且link_to不起作用,在以前的应用程序中起作用了,也许我在route.rb中做得不好?

Any ideas? 有任何想法吗? Thanks! 谢谢!

And can it be added some confirmation, like "Are you sure?" 并可以添加一些确认信息,例如“您确定吗?” to button_to helper? 到button_to助手?

布局模板的整个头部都被注释掉了,这意味着javascript include被注释掉了,这意味着没有在将魔术添加到:method => :delete链接的JS上运行。

can you view html source in your web browser when the page actually get rendered? 实际呈现页面时,您能否在Web浏览器中查看html源代码? you should see references to your jQuery source files, if you are using jQuery. 如果您使用的是jQuery,则应该看到对jQuery源文件的引用。

for example:

<script src="/public/javascripts/jquery.js?body=1" type="text/javascript"></script>
<script src="/public/javascripts/jquery_ujs.js?body=1" type="text/javascript"></script>

Then, check if there exists these physical jquery source files or not? 然后,检查是否存在这些物理jquery源文件? Those could have been missing. 那些可能已经不见了。 If this will be the case, just copy over those missing files to their intended locations. 如果是这种情况,只需将那些丢失的文件复制到其预期位置。

hope this help. 希望有帮助。

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

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