Domanda

I have the following in my view (index.html.erb) code:

<% @projects.each do |project| %>
   <%= link_to (@project) do %>
      <div id="tombstone">
         ...Some HTML here...
      </div>
   <% end %>
<% end %>

The goal is to have each project's synopsis displayed inside the tombstone DIV and have the entire DIV act as the link to the project's details page (show.html.erb).

My Controller has the following:

def show
   @project = Project.find(params[:id])
end

and the routes has the following:

resources :projects do
   ...
   resources :updates
end

The @project in the <%= link_to %> points back to the projects (index.html.erb) page, not to the project details page (show.html.erb) that the controller defines. I can only guess that the ID parameter isn't getting passed, but I can't figure out why.

È stato utile?

Soluzione

<%= link_to(project) do %> # not @project

Technically you've been sent to index because @project probably new record. @project == Project.new, so link_to(Project.new) with GET request renders path to index action.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top