문제

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

도움이 되었습니까?

해결책

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.

다른 팁

Just specify the right route pattern for that second case and make sure you keep in mind that the mappings are evaluated from top to bottom (first match gets executed).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top