Reputation: 47
I got a problem with a link I've tried to make. I want to have a page with an article, and a link to the author page of it. Iv's try 100 differents version but i don't know how to do... Here is my code :
<a <% link_to " Par : #{@article.author.pseudo}", user_path(User.where(user_id: @author_id) %></a>
or with this path : user_path(Article.find(params[:id]).author_id)
If you know how I can resolve that... Thanks !
Upvotes: 2
Views: 137
Reputation: 302
Try something like this:
<%= link_to("Par : #{@article.author.pseudo}", @article.author) %>
Upvotes: 0
Reputation: 4640
Don't wrap link_to helper into <a>
tag, it is already generated by the helper. where
returns the collection, not the instance - that's why your code does not work. You already have needed user instance in @article.author
, just use it
<%= link_to "Par : #{@article.author.pseudo}", user_path(@article.author) %>
Upvotes: 2
Reputation: 3057
You should be able to link directly to the author:
<%= link_to "Par : #{@article.author.pseudo}", @article.author %>
Upvotes: 1