【问题标题】:Why isn't `link_to` going to the route I've specified为什么 `link_to` 不去我指定的路线
【发布时间】:2013-09-29 05:47:09
【问题描述】:

我有这些路线从运行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 操作?

【问题讨论】:

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


    【解决方案1】:

    试试

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

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

    【讨论】:

      【解决方案2】:

      我认为您想要以下内容:

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

      看起来你在你的 routes.rb 中生成了一个单一的资源......这是故意的吗?

      【讨论】:

        猜你喜欢
        • 2011-03-18
        • 2020-07-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-18
        • 1970-01-01
        相关资源
        最近更新 更多