I have an article model that has a title, body, author and category fields. All of the articles are grouped by their category which means i have 6 pages like “news”, “bulletin” “sport” etc.
How could I link to an articles category page from its show page?
articlesController.rb
def news
@articles = Article.paginate(page: params[:page], per_page: 7).where(category: "News")
end
rake routes & routes.rb
news /news(.:format) articles#new
match '/news', controller: "articles", action: "news"
link
<b><%= link_to @article.category, @article.category_path?? %></b>
Thanks in advance!
With rails 2
This will give your
news_pathorbulletin_path. In a particular function, you can load thearticle_categoryas well as all its articles.Make a helper method
category_pathlike belowand links like