简体   繁体   English

Rails嵌套路由错误

[英]Rails nested routing error

I am trying to build a forum while nesting the routes and I keep running into this error: 我试图在嵌套路线的同时建立一个论坛,但我不断遇到此错误:

undefined method `forum_threads_path' for 未定义的方法'forum_threads_path'

I have nested my routes as so in my routes.rb file 我已经在我的routes.rb文件中嵌套了我的路由

 resources :forum_subjects do
    resources :forum_threads, module: :forum_subjects do
      resources :forum_msgs, module: :forum_threads
    end
  end

I am trying to call this using form_for in a partial of the _form.html.erb 我试图在_form.html.erb的一部分中使用form_for来调用它

<%= form_for [@forum_subject, @forum_thread] do |f| %>

My view files are also located in folders within the one main one: forum_subjects/forum_threads/forum_posts where all the view files are also nested. 我的视图文件也位于一个主要文件夹中的文件夹中: forum_subjects / forum_threads / forum_posts ,其中所有视图文件也都嵌套在其中。

The error you are getting is correct. 您得到的错误是正确的。 Since, your forums_threads is nested inside forum_subjects you will not be able to call the forum_threads_path. 由于您的forums_threads嵌套在forum_subjects内,因此您将无法调用forum_threads_path。 You will be able to find out the correct method to call if you run the rake routes in the terminal by changing directory to your project. 如果您通过将目录更改为项目在终端中运行耙路径,则将能够找到正确的调用方法。 Ideally there will be a method called forum_subject_forums_threads_path. 理想情况下,将有一个名为forum_subject_forums_threads_path的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM