【问题标题】:undefined local variable or method `on' for #<ActionDispatch::Routing::Mapper:0x007fd3b4516a00>#<ActionDispatch::Routing::Mapper:0x007fd3b4516a00> 的未定义局部变量或方法“on”
【发布时间】:2017-07-08 05:42:13
【问题描述】:

我正在尝试将控制器的编辑操作替换为具有额外参数的控制器,但我得到:

undefined local variable or method `on' for #<ActionDispatch::Routing::Mapper:0x007fd3b4516a00>

这是 routes.rb 部分:

resources :structures, except: :edit do
  get '/:doctype' => :edit, on: :edit
end

问题是:编辑。使用 :new 之类的其他操作非常有效。

【问题讨论】:

    标签: ruby-on-rails routing


    【解决方案1】:

    你可以试试这个:

    resources :structures, except: :edit do
      get '/edit/:doctype' => :edit
    end
    

    您尝试使用的语法旨在与on: (new|member|collection) 一起使用。 edit 在这里不是一个有效的选项。

    【讨论】:

    • 如果您输入错误“member”,您还会看到 OP 的错误。仔细检查你的拼写!
    猜你喜欢
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多