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

  • SEARCH
  • Home
  • 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 4116182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:40:36+00:00 2026-05-20T22:40:36+00:00

Should my URL’s in Rails look like: http://foobar.com/articles?category=recent – OR – http://foobar.com/articles/recent I find

  • 0

Should my URL’s in Rails look like:

http://foobar.com/articles?category=recent 

– OR –

http://foobar.com/articles/recent

I find the former to be more RESTFUL, but the latter to be more cleaner (code-wise). For example, the code can look like:

In Article controller:

def index
  if params[:category] == 'recent'
    @articles = Article.by_recent
  elsif params[:category] == 'expired'
    @articles = Article.by_expired
  end
end

In Article, index view:

<% unless @articles.blank? %>
  <ul>
    <% @articles.each do |article| %>
      <li><%= article.title %></li>
      <li><%= article.content %></li>
    <% end %>
  </ul>
<% end %>

With http://foobar.com/articles/recent, I would have to customize my routes. Something like:

match 'articles/:category' => 'articles#index' 

Above will access the Article controller, index action. Or even:

resources :articles do
  collection do
    get 'recent'
  end
end

Which will allow for urls like http://foobar.com/articles/recent, but needs a ‘recent’ action in the Article controller.

Both seem pretty useful, in the end of the day. But which is the general consensus? Using the query string approach (http://foobar.com/articles?category=recent) or the other way (http://foobar.com/articles/recent).

Looking forward to your suggestions.

  • 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-05-20T22:40:36+00:00Added an answer on May 20, 2026 at 10:40 pm

    Obviously like you said you could go either way, but since something like “recent” is a condition of or query against articles I would go with the former. If it were a nested attribute and its own model the second approach is arguably better, but since it isnt you really lose a lot of flexibility to change and refactor the approach down the road.

    For instance if you wanted to do “old” as opposed to “recent” you would not be able to simply pass in an “old” parameter, but would have to hardcode that with its own action and views in the same controller as “recent” which is of course a lot more work for nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.