1

I have two different syntax both referring to same url

 <%= link_to 'Back', articles_path %>

<%= link_to 'My Blog', controller: 'articles' %>

What is the differences between the two approaches , which one should be use when. where is articles_path stored ?

1
  • run rake routes in console and see the magic Commented Jul 17, 2014 at 5:22

1 Answer 1

3

Both syntax does the same thing they will take you to /articles.

Which ones better

Since both does the same thing so it really depends on you which one to use but if you look at docs it says 1st syntax

<%= link_to 'Back', articles_path %>

is better because it's less verbose.

What is articles_path

articles_path is just a rails helper which rails creates for you when you make a route. As @nithin suggested if you run rake routes in your terminal you can see those helper methods.

If you'll use articles_url it will give you pull url like domain/articles and if you'll use articles_path then it'll give you a relative url /articles

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.