0

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.

1
  • link_to project_path(project) do ? Commented Dec 21, 2012 at 21:19

1 Answer 1

2
<%= 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Heh, Noob error. But then again, I am a Noob. (6 weeks on Rails and loving it!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.