【问题标题】:Error says there is no routes, but it seems there is错误说没有路线,但似乎有
【发布时间】:2013-01-14 11:18:51
【问题描述】:

我有以下表单声明:

<%= semantic_form_for @contrat_line, 
    :url => url_for(:controller =>"/backend/orders/#{@contrat.id}/contrat_lines", 
        :action =>"create") do |f| %>

我想走以下路线:

POST    /backend/orders/:order_id/contrat_lines(.:format)   backend/contrat_lines#create

但是当我想显示表单时出现以下错误(甚至在使用它之前):

No route matches {:controller=>"backend/orders/23/contrat_lines", :action=>"create"}

我会说这条路线存在,为什么说它不存在?

【问题讨论】:

  • 出了点问题:orders/#{@contrat.id}orders/:order_id
  • 我已经试过了,错误变成:No route matches {:controller=>"backend/orders/:order_id/contrat_lines", :action=>"create"}
  • 你确定contrat的拼写吗?似乎您在那里缺少c
  • 不是我的语言,我知道我应该用英语。

标签: ruby-on-rails routing nested


【解决方案1】:

routes.rb 代码

match "/backend/orders/:order_id/contrat_lines" => "orders#contrat_lines", :as => "contrat_lines"

然后,查看代码

<%= semantic_form_for @contrat_line, 
    :url => contrat_lines_url(:order_id => @contrat.id), 
        :action =>"create") do |f| %>

【讨论】:

    【解决方案2】:

    感谢salil,我设计了以下表格:

    backend_order_contrat_lines_url(:order_id => @contrat.id), :action =>"create" do |f| %>

    它适用于那些路线:

    namespace :backend do
        resources :orders do
          resources :contrat_lines
        end
    end
    

    非常感谢!如果您愿意,我可以编辑您的答案并将其设置为已接受。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2019-04-21
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      相关资源
      最近更新 更多