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'

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.