【问题标题】:html slim link_to undefined method errorhtml slim link_to 未定义方法错误
【发布时间】:2018-08-07 20:32:12
【问题描述】:

在我的 rails 项目中,我运行 rake routes 并得到以下输出:

 Prefix Verb   URI Pattern                                              Controller#Action
obelisk_callflow_nodes GET    /obelisk/callflows/:callflow_id/nodes(.:format)          obelisk/nodes#index
                       POST   /obelisk/callflows/:callflow_id/nodes(.:format)          obelisk/nodes#create
new_obelisk_callflow_node GET    /obelisk/callflows/:callflow_id/nodes/new(.:format)      obelisk/nodes#new
edit_obelisk_callflow_node GET    /obelisk/callflows/:callflow_id/nodes/:id/edit(.:format) obelisk/nodes#edit
 obelisk_callflow_node GET    /obelisk/callflows/:callflow_id/nodes/:id(.:format)      obelisk/nodes#show
                       PATCH  /obelisk/callflows/:callflow_id/nodes/:id(.:format)      obelisk/nodes#update
                       PUT    /obelisk/callflows/:callflow_id/nodes/:id(.:format)      obelisk/nodes#update
                       DELETE /obelisk/callflows/:callflow_id/nodes/:id(.:format)      obelisk/nodes#destroy
     obelisk_callflows GET    /obelisk/callflows(.:format)                             obelisk/callflows#index
                       POST   /obelisk/callflows(.:format)                             obelisk/callflows#create
  new_obelisk_callflow GET    /obelisk/callflows/new(.:format)                         obelisk/callflows#new
 edit_obelisk_callflow GET    /obelisk/callflows/:id/edit(.:format)                    obelisk/callflows#edit
      obelisk_callflow GET    /obelisk/callflows/:id(.:format)                         obelisk/callflows#show
                       PATCH  /obelisk/callflows/:id(.:format)                         obelisk/callflows#update
                       PUT    /obelisk/callflows/:id(.:format)                         obelisk/callflows#update
                       DELETE /obelisk/callflows/:id(.:format)                         obelisk/callflows#destroy

我有一个 html.slim 文件用于显示所有调用流(即 obelisk/nodes#index)。在这个文件中,我想添加一个按钮来显示每个调用流的节点(即将该按钮连接到obelisk_callflow_nodes GET /obelisk/callflows/:callflow_id/nodes

我试过= link_to 'Nodes', obelisk_callflow_nodes_path(callflow_id: c.id), method: :get, class: 'btn btn-primary' 其中c 是一个调用流对象。我已经检查了 c 是我想要的,因为我有 c.name 正确渲染。但是,我收到以下错误:

undefined methodobelisk_callflow_nodes_path' 用于#`

我已经检查过我的 Obelisk::NodesController 确实有一个索引方法

【问题讨论】:

  • 试试这样obelisk_callflow_nodes_path(c.id),你不需要设置参数的名称,只需按照它们在路由中配置的顺序传递它们
  • 停止 rails 服务器,然后 spring stop 并再次启动服务器。试试这个。
  • 试过 obelisk_callflow_nodes_path(c.id) 并得到错误 undefined method `obelisk_callflow_nodes_path' for #:0x00007efc4092ceb0>
  • 你确定 c.id 有一个有效的 id 吗?你能把错误的屏幕截图吗?
  • 可以显示服务器日志吗?

标签: html ruby-on-rails ruby slim-lang


【解决方案1】:

我更改了路线,因此我不再使用 namespace obelisk,因此路线不以 /obelisk/ 开头。这解决了问题。我知道这可能不是最好的解决方案,但在这种情况下,它已经为我的项目工作。

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 2015-10-18
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多