Search code examples
ruby-on-railsruby-on-rails-3nested-resources

Rails 3 multi nested resource form


I have got such routes:

  resources :projects do
    resources :chats
    resources :lists do
      resources :issues
    end
  end

Now I am trying to setup proper form to add issue to list, but I do not know how... Currently it looks like this:

Controller:

def show
    @project = Project.find(params[:id])
    @list = List.new
    @issue = @list.issues.build


    @chats = @project.chats
    @lists = @project.lists.includes(:issues)


    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @project }
    end
  end

Form

form_for [@list, @issue], remote: true do |f|

And I get error like this:

undefined method `list_issues_path' for #<#<Class:0x00000003996f30>:0x000000038ad678>

How should I solve it? Thanks in advance!


Solution

  • I believe that is because it would need to be nested under the project. If you run rake:routes I imaging you have something like projects/:id/lists/:id/issues/? You can see what the name of the route is next to that. Otherwise you can add the shallow option to the lists route.