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

Don Neethling
Don Neethling
6,164 Points

path helpers query

this is from my routes.rb file

Rails.application.routes.draw do
  get '/', to: 'contacts#index'
  get '/:id', to: 'contacts#show', as: 'shows'
end 

and this is from my erb file

<% @contacts.each do |individual| %>
    <p><%= link_to individual.lname, shows_path(individual) %></p>
    <% end %>

The above works fine

However, when I pass the "individual" object to the link_to method as follows

<% @contacts.each do |individual| %>
    <p><%= link_to individual.lname, individual %></p>
    <% end %>

Which as stated by Jay below is supposed to work

"We can even skip calling page_path explicitly and just pass the page object as an argument to link two. Behind the scenes link two will call page_path on the object for us."<

I get the following error

undefined method `contact_path' for #<#<Class:0x007f974f780df0>:0x007f9754b0f228> Did you mean? controller_path

Extracted source (around line #4):

<% @contacts.each do |individual| %> <p><%= link_to individual.lname, individual %></p> <% end %>

Please let me know what I am overlooking in this case.