Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Nested Attributes Links on a Static Page/Profile Page

I have a nested model system and a Static Page.

My models are:

User model:

has_many :collections
has_many :designs, :through => :collections

Collection model:

belongs_to :user
has_many: designs

Designs model:

belongs_to :user
belongs_to :collection

The static page is supposed to show ALL of every users Designs, and it does. Unfortunately, the links are broken..maybe I just am doing something wrong in the controller??

Here is the static pages controller for the page that shows all of the designs:

def home
  if signed_in?
    @designs = Design.all
  end
end

I've also tried to add these line (different times) before the @designs line:

@collection = Collection.all


@collection = Collection.find(params[:collection_id])

Here is the view for the static pages (the form at least):

<% @designs.each do |design| %>
  <fields are here>
<% end %>

Why are the links broken? As mentioned, everything looks great on the page except for the links.

To show a design:

link_to collection_design_path(@collection, design)

but this turns into:

myURL/collections//designs/:id

It should look like:

myURL/collections/:id/designs/:id

The first id is the collection's id and the second id is the design's id:

The collection id is not being used in the links. Any ideas on how to fix this???

1 Answer

I figured it out...on static pages my links should have looked like this

collection_design_path(design.collection, design)