Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8675347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:55:40+00:00 2026-06-12T19:55:40+00:00

I have an article model that has a title, body, author and category fields.

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:55:41+00:00Added an answer on June 12, 2026 at 7:55 pm

    With rails 2

    #routes.rb
    map.news       'news',     :controller => "Articles", :action => "news"
    map.bulletin   'bulletin', :controller => "Articles", :action => "bulletin"
    

    This will give your news_path or bulletin_path. In a particular function, you can load the article_category as well as all its articles.

    Make a helper method category_path like below

    def category_path(article)
        return eval("#{article.category.downcase}_path")
    end
    

    and links like

    <%= link_to @article.category, category_path(@article) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model Article it has field title with some text that may contain
Trying to get all articles, with unique titles (distinct(title)), that have a body of
I have an Article model that has a foreign key relationship with Author that
I have a model Articles that has_many Assets which is a polymorphic model that
Just starting out here, I have a Article.rb model that stores articles. So it
I have an article controller that deals with articles. I have a comment model
Lets say I have a model, Article that has a large amount of columns
I have a weird design question. I have a model called Article, which has
I have two model: User, Article A user can like or dislike many articles,
I have the following listview : http://www.vogella.de/articles/AndroidListView/article.html the chaper: 8. Tutorial: Domain Model and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.