# Rails 7: Nested resources/forms not working

**URL:** <https://discuss.rubyonrails.org/t/rails-7-nested-resources-forms-not-working/79880>\
**Category:** rubyonrails-talk\
**Created:** [January 26, 2022, 9:45pm UTC](https://discuss.rubyonrails.org/t/rails-7-nested-resources-forms-not-working/79880 "2022-01-26T21:45:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![piet](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@piet](https://discuss.rubyonrails.org/u/piet)\
**Post date:** [January 26, 2022, 9:45pm UTC](https://discuss.rubyonrails.org/t/rails-7-nested-resources-forms-not-working/79880/1 "2022-01-26T21:45:18Z")

</div>

Hi,

i have three models:

```ruby

class Checklist < ApplicationRecord
  belongs_to :page
	has_many :groups

	has_rich_text :description

#	validates_presence_of :title
end

class Group < ApplicationRecord
  belongs_to :checklist
end

class Page < ApplicationRecord
	has_many :checklists
	has_rich_text :description
end

```

A page can have one or many checklists. A Checklist can have one or more Groups.

All Associations are created.

On the pages editpage i created a form like this:

```ruby
<% @page.checklists.each do |cl| %>

    <%= form_with(model: [@page, cl]) do |f| %>

        .... more code => text fields etc

    <% end %>

<% end %>

```

And the checklist controller:

```ruby
def create

    @page = Page.find(params[:page_id])

    @checklist = @page.checklists.build

   

    if @checklist.save

      notice = nil

    else

      notice = @checklist.errors.full_messages.join('.') << '.'

    end

    redirect_to edit_page_path(@page), notice: notice

  end

```

There I can easily create a checklist for this page.

&nbsp;

* * *
&nbsp;

Now i want to do the same with groups for checklists. But there is my problem, it won’t work.

Here is the form:

```ruby
<%= form_for [@page, @checklist, @group] do |form|%>
    ... more code => text fields etc
<% end %>

```

This is my create action for groups:

```ruby
def create
    @page = Page.find(params[:page_id])
	@checklist = Page.checklists.find(params[:checklist_id])
    @group = @checklist.groups.build

    if @group.save
		notice = nil
    else
		notice = @group.errors.full_messages.join('.') << '.'
    end
		redirect_to edit_page_checklist_path(@checklist), notice: notice
  end

```

Is there any other code needed to help me?

---

<div class="post-metadata">

**Author:** ![swobspace](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/swobspace/32/4682_2.png) [@swobspace](https://discuss.rubyonrails.org/u/swobspace)\
**Post date:** [February 6, 2022, 8:56am UTC](https://discuss.rubyonrails.org/t/rails-7-nested-resources-forms-not-working/79880/2 "2022-02-06T08:56:07Z")

</div>

Do you have something like

```ruby
resources :pages do
  resources :checklists do
    resources :groups
  end
end

```

in your `routes.rb`? I would avoid double nested resources.

```ruby
<%= form_for [@checklist, @group] do |form| %> 

```

should be enough to create a group, since `@checklist` is always linked to a page. Second, `edit_page_checklist_path` needs the page as param. Without double nesting you don’t have `@page`, but you can take it from `@checklist`:

```ruby
redirect to edit_page_checklist_path([@checklist.page, @checklist]), notice: notice

```
