On 1 June 2012 17:22, Rodrigo Rosenfeld Rosas <[email protected]> wrote:
> Em 01-06-2012 13:20, Jeremy Walker escreveu
>
> But in the CoffeeScript, the developer will know the id of the resource
> they're calling.
>
> So, the CS:
> $.get project_path(project.id)
>
> ...could be pre-processed, using a lookup in routes.rb, into:
> $.get "projects/#{project.id}"
>
> ...which then gets compiled to:
> $.get "projects/" + project.id
>
> And voila, you have a working solution. Am I missing something? :)
>
>
> Yes, the id will be inside a JS variable. So if you have some constraints
> like /\d+/, it won't be able to check them...
>
Good point. Am I correct in saying that the only time this is a real issue
is if someone defines two routes, with the same name, but different paths,
e.g.
match '/products/:id' => 'products#show', :constraints => {:id => /\d/},
as: "product"
match '/products/:id/extra' => 'products#show', as: "product"
In other situations, the generated path will be the same, and the server
will still check the constraint if/when the request is sent, so the
developer loses a little compile-time type-safety, but everything stays
safe/secure.
Obviously, the two different routes with the same name thing is an issue,
but that idiom strikes me as a bit odd/risky in the first place.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.