简体   繁体   中英

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

I have nested my routes as so in my routes.rb file

 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_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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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