【问题标题】:Named route from resources takes me to show page instead of delete page来自资源的命名路由让我显示页面而不是删除页面
【发布时间】:2011-03-29 21:29:40
【问题描述】:

我在routes.rb 中使用resources :users。随着rake routes 的揭幕,这提供了以下路径。

users     GET    /users(.:format)           {:action=>"index", :controller=>"users"}
          POST   /users(.:format)           {:action=>"create", :controller=>"users"}
new_user  GET    /users/new(.:format)       {:action=>"new", :controller=>"users"}
edit_user GET    /users/:id/edit(.:format)  {:action=>"edit", :controller=>"users"}
user      GET    /users/:id(.:format)       {:action=>"show", :controller=>"users"}
          PUT    /users/:id(.:format)       {:action=>"update", :controller=>"users"}
          DELETE /users/:id(.:format)       {:action=>"destroy", :controller=>"users"}

此外,我注释掉旧的野控制器路由。

#match ':controller(/:action(/:id(.:format)))'

要在我的用户页面上添加 删除 链接,我添加以下内容。

<%= link_to "Delete user", user, :method => :delete, :confirm => "Are you sure?" %>

这会生成以下 html 代码。

<a href="/users/42" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete user</a>

我点击该链接,它会将我带到显示页面?!怎么了?

【问题讨论】:

    标签: ruby-on-rails-3 routes resources restful-url


    【解决方案1】:

    您需要包含默认的 Javascript 文件才能正常工作:

    <%= javascript_include_tag :defaults %>
    

    【讨论】:

      猜你喜欢
      • 2011-11-10
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      相关资源
      最近更新 更多