Em 01-06-2012 13:45, Jeremy Walker escreveu:


On 1 June 2012 17:22, Rodrigo Rosenfeld Rosas <[email protected] <mailto:[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 <http://project.id>)

    ...could be pre-processed, using a lookup in routes.rb, into:
    $.get "projects/#{project.id <http://project.id>}"

    ...which then gets compiled to:
    $.get "projects/" + project.id <http://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.

Yeah, that would work.

I just thought you were suggesting to use produc_path(id) for implementing this feature. In that case, it would raise an exception if id is not a number.

How are you thinking about the implementation of such feature while processing CS?

Also, what if someone still wants to keep using JS instead of CS? How would it be possible for them to take advantage of the asset pipeline route helpers?

--
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.

Reply via email to