我在Rails中的动词遇到了麻烦 ......
查看资源(狗)的页面has_many(跳蚤).嵌入在狗中的show.html.haml是一个render @dog.fleas自动(?)查找并使用"fleas/_flea.html.haml"中的模板来列出与所述狗相关的每个跳蚤的调用.
这显示正确.噢!现在,在每个跳蚤的旁边,我放了一个"Kill Flea"链接进入网址://localhost:3000/dogs/1/fleas/7.由哪个生成:
= link_to("Kill Flea", [ flea.dog, flea ], :method => :delete, :confirm => "Sure? A bunny will die")
Run Code Online (Sandbox Code Playgroud)
但是每次点击该链接都没有确认...并且它会呈现跳蚤的show.html页面.这是因为如果它使用GET上/dogs/1/fleas/7,而不是删除?!?
ps-不担心蜘蛛和机器人在我的数据库中删除东西......我只是想学习Rails ......并了解发生了什么
单击"注销"时出现以下路由错误:
No route matches [GET] "/logout"
Run Code Online (Sandbox Code Playgroud)
这是我的application.html.erb文件:
<% if session[:user_id] %>
<%= link_to 'Logout', logout_path, :method => :delete %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是我的routes.rb文件:
get 'admin' => 'admin#index'
controller :sessions do
get 'login' => :new
post 'login'=> :create
delete 'logout' => :destroy
end
get "sessions/create"
get "sessions/destroy"
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?