为什么`link_to`没有进入我指定的路线

时间:2013-09-24 06:24:08

标签: ruby-on-rails ruby controller routing views

我有这些路线来自rake routes

     workstations POST   /workstations(.:format)      workstations#create
 new_workstations GET    /workstations/new(.:format)  workstations#new
edit_workstations GET    /workstations/edit(.:format) workstations#edit
                  GET    /workstations(.:format)      workstations#show
                  PUT    /workstations(.:format)      workstations#update
                  DELETE /workstations(.:format)      workstations#destroy
                  POST   /                            workstations#delete_history_and_queue

我认为我有link_to

= link_to "Update", controller: "workstations", method: "put"

然而我收到了这个错误:

No route matches {:controller=>"workstations", :method=>"put"}

我是否未指定将workstations控制器与put方法一起使用的链接,理论上这应该导致workstations#update操作?

2 个答案:

答案 0 :(得分:1)

尝试

= link_to "Update", edit_workstations_path, :method => :put

OR

= link_to "Update", '/workstations', :method => :put

答案 1 :(得分:0)

我想你想要以下内容:

= link_to "Update", workstations_path, :method => :put

看起来你在你的路线中生成了一个奇异的资源.rb ......是故意的吗?