Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Named Routes in routes.rb shows syntax error in actionpack

#6517

I have a named route in my routes.rb file like

  match "/orders/summary_sales/:event_id.:format" => "orders#summary_sales", :as => "formatted_summary_sales"

If i leave a space after "formatted_summary_sales" in :as option like below

  match "/orders/summary_sales/:event_id.:format" => "orders#summary_sales", :as => "formatted_summary_sales "

and if i run "rake routes", the following error occurs.

Invoke routes (first_time) Invoke environment (first_time) ** Execute environment rake aborted!
/Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:161: syntax error, unexpected '(', expecting ';' or '\n' ...r_formatted_summary_sales url(options = nil) ... ... ^ /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:161: syntax error, unexpected ')', expecting $end ...mmary_sales url(options = nil) ... ... ^ /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:160:in module_eval' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:160:indefine_hash_access' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:151:in block in define_named_route_methods' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:149:ineach' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:149:in define_named_route_methods' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:100:inadd' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/route_set.rb:300:in add_route' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/mapper.rb:273:inmatch' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/mapper.rb:1173:in match' /Users/lakshmanan/.rvm/gems/ruby-1.9.2-p136@da3/gems/actionpack-3.0.5/lib/action_dispatch/routing/mapper.rb:1358:inmatch' /Users/lakshmanan/projects/da/config/routes.rb:92:in `block in '

Strange. But if I i dont give that space, I get the proper rake routes ouput.

Reported by lakshmanan · March 4th, 2011 @ 07:11 AM

State: resolved
Milestone: 3.x
Assigned to: Andrew White Andrew White
Importance: Low

Activity

  1. lakshmanan
    lakshmanan

    It actually shows a syntax error. The title of this ticket should have been like "Named Routes in routes.rb shows syntax error actionpack"

    March 4th, 2011 @ 08:00 AM

  2. Aditya Sanghi
    Aditya Sanghi
    • Title changed from Named Routes in routes.rb shows syntax actionpack to Named Routes in routes.rb shows syntax error in actionpack
    • Importance changed from to Low

    March 4th, 2011 @ 09:59 AM

  3. Andrew White
    Andrew White
    • State changed from new to open
    • Milestone set to 3.x
    • Assigned user changed from Santiago Pastorino to Andrew White

    What's happening is the :as option is used as the named route helper method name. The fix is to raise an ArgumentError when the route is being defined if the :as option is not a valid method name. I'll fix this over the weekend.

    March 4th, 2011 @ 11:03 AM

  4. Diego Carrion
    Diego Carrion

    I attached a patch in case the expected behavior is not to break.

    March 6th, 2011 @ 05:10 AM

  5. Andrew White
    Andrew White

    Thanks, Diego but I think it's better to raise an exception - the name may be invalid for other reasons such as a leading number, space in the middle, etc.

    March 6th, 2011 @ 05:17 AM

  6. lakshmanan
    lakshmanan

    @Diego +1

    I think, at least we must :strip the name before considering. Deigo's patch does exactly that.

    March 6th, 2011 @ 06:03 AM

  7. Andrew White
    Andrew White

    But if you just strip the name your routes.rb file is left with an invalid argument - something I'd prefer to know.

    March 6th, 2011 @ 06:16 AM

  8. Repository
    Repository
    • State changed from open to resolved

    March 6th, 2011 @ 07:26 AM

  9. Repository
  10. Repository
    Repository

    (from [9cee693213e0205cb5992728bb516215e34cb79f]) Merge branch 'master' of github.com:rails/rails

    • 'master' of github.com:rails/rails: (44 commits) Fixed indentation in actionmailer base_test [#6538 state:committed] remove unused assigned variable removes merge conflicts removes Examples headers introduced in 9b96de6 Revert "Fixed identation in actionmailer base_test" Report the correct value of nil.id in the exception message as different ruby implementations may have different values, for example Rubinius returns 53 for nil.id. Improve testing of cookies in functional tests: - cookies can be set using string or symbol keys - cookies are preserved across calls to get, post, etc. - cookie names and values are escaped - cookies can be cleared using @request.cookies.clear more style changes Some style changes style changes Revert "style changes" Raise ArgumentError if route name is invalid [#6517 state:resolved] style changes Allow model to be inherited from Hash [#6487 state:resolved] styles applied for usage added failing test for fields_for with a record object that inherits from Hash Fixed identation in actionmailer base_test wrong SQL statement commas to set off expressions that interrupt sentence flow typo changes ... https://github.com/rails/rails/commit/9cee693213e0205cb5992728bb516...

    March 7th, 2011 @ 04:51 PM