Good Morning,

Rails route URL helpers are great. Their API is concise and intuitive.
I believe that we should have that API available in Javascript too:

users_path()                                       // => "/users"
user_path(1)                                       // => "/users/1"
user_path(1, {format: 'json'})                     // => "/users/1.json"
user_path(1, {anchor: 'profile'})                  // => "/users/1#profile"
new_user_project_path(1, {format: 'json'})         // => 
"/users/1/projects/new.json"
user_project_path(1,2, {q: 'hello', custom: true}) // => 
"/users/1/projects/2?q=hello&custom=true"
user_project_path(1,2, {hello: ['world', 'mars']}) // => 
"/users/1/projects/2?hello%5B%5D=world&hello%5B%5D=mars"



Most Rails projects I know hardcode routes in Javascript, some pass those 
routes from HTML as data attributes.
Like:

jQuery.get("/posts/" + post.id + "/comments/" + comment.id + ".json", 
function(){ ...});
// slightly better
jQuery.get($(this).data("url"), function(){ ...});




But I believe that extensive use of JS should require URL helpers. 

Here is the "prototype" 8 years old project I 
maintain: https://github.com/railsware/js-routes
But I believe 90% of Rails projects need that out of the box now.

What do you think about adding the functionality to the Rails core?


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to