Search code examples
ruby-on-railsroutescontrollers

adding and accessing controllers in ruby on rails


If I have a controller, how do I access it via URL with newly added methods?

Reason I am confused is because I have a route,

map.connect 'assignments/:external_id.:format', :controller => "assignments", :action => "show", :external_id => /\d{6}/

It seems that I can't access any other method within the assignments controller because if i do

mysite.com/assignments/other_method

It'll assume that other_method is an ID I'm passing into the show controller, as specified in the route entry above.

Edit:

I added this to the top:

map.connect 'assignments/send/', :controller => "assignments", :action => "send"

and am now getting this error:

ArgumentError in AssignmentsController#show 

The route for assignments/send is the first declration for any of the assignments controller


Solution

  • Your routing table should have it in this order

    map.connect 'assignments/:external_id.:format', :controller => "assignments", :action => "show", :external_id => /\d{6}/
    
    map.connect 'assignments/send/', :controller => "assignments", :action => "send"
    

    to end with

      map.connect ':controller/:action/:id'
      map.connect ':controller/:action/:id.:format'
    

    as your most general case.