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 8446245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:52:44+00:00 2026-06-10T09:52:44+00:00

New to rails, so if this is discussed somewhere, just link me off: I

  • 0

New to rails, so if this is discussed somewhere, just link me off: I had a good search but all I could find were people trying to figure out how to use link_to, not any discussion of this comment:

link_to "Profile", profile_path(@profile)
# => <a href="/profiles/1">Profile</a>

in place of the older more verbose, non-resource-oriented

link_to "Profile", :controller => "profiles", :action => "show", :id => @profile
# => <a href="/profiles/show/1">Profile</a>

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

I get that the latter is more verbose, and thus undesirable, but the former seems like a strange thing to be recommending.

If I have an action at say: /blah/add and I link to it using:

link_to "Link", link_add_path

Then I’m linking to mysite.com/link/add. This is a hard coded url.

If I change the route that this maps to, I have to change every instance of link_to in my code base to point to the new absolute url. This seems crazy.

However, if I link to it using:

link_to "Link", :controller => "thing", :action => "add"

Then the url is dynamically determined. If I have to change the path all I do is edit config/routes.rb and not touch any of my code. This seems like much lower maintenance.

I appreciate it’s slightly more complex than that, the blah_path variable is not actually a static route, and actually contains some smarts like the application base url and prevents you from linking to urls that don’t exist, but it seems like a step backwards to facilitate a fractionally less verbose syntax.

So, what’s up with that?

What technical reason would you choose the former link_to syntax over the latter?

  • 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-10T09:52:45+00:00Added an answer on June 10, 2026 at 9:52 am

    “You’re doing it wrong” 😛

    Seriously though: use named resources, and here’s why that’s cool:

    Example:
    you’ve got this in your routes file:

        resources :user_orders
    

    And you are using “user_orders_path” everywhere. Then you do a refactor and decide (because the orders are now generic) that you want the controller to be called “orders” but you don’t want to break all your old code. you can do this:

        resources :user_orders, controller: "orders"
    

    And your existing links will continue to work! (plus you can add a “orders” resource to move things over to the new scheme)

    There’s also neat things like named links:

        match 'exit' => 'sessions#destroy', :as => :logout
    

    I’d also like to add, if you needed to refactor your controller using the old link syntax – you’d still have to change a pile of controller links!

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

Sidebar

Related Questions

I run rails new search in my console, and I get all of this:
I'm a bit new to Rails/RSpec/Capybara, so this is probably a newbie question, but
I am new to rails and read this guide to get all the info
I am new to Rails so this is probably an easy question but can't
I'm new to Rails and this maybe a dumb question, but I wonder how
Ok...I am new to rails so this may be a stupid question but need
I am pretty new to rails so this may be an easy question, but
Im new to rails so this may seem like a silly question but why
I'm pretty new to rails and this is also my first post, but I'm
New Rails programmer here. There is probably a pretty simple solution to this, but

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.