How does this rails route match any incoming action to it's correlated method on the controller? -
i have rails route defined this:
match '/test_report(/:action)' => 'test_report#index', via: :all
i not expert on rails routing, using context clues have expected route map request /test_report/some_action
or /test_report/other_action
index
method on testreportcontroller
, because of part of route definition after hash rocket: => 'test_report#index'
.
however, not behavior. instead, can create method on testreportcontroller
called update_report
, , can post
/test_report/update_report
trigger update_report
method. route definition i'm using, wouldn't expect work, does. have expected post
hit index
method on controller.
note: we're clear, understand (/:action)
part of route marks optional part of url, , :action
symbol special here , interpreted action's name.
tl;dr:
if => 'test_report#index'
in above route doesn't map requests index
method on controller, do?
as know, whatever parameters define within route pattern become available in params
hash in controller.
so in example, :action
becomes available within controller params[:action]
, used internally rails load correct action. (if inspect, you'll see params[:route]
, params[:controller]
, params[:action]
, etc.)
i'm guessing defining own :action
in url pattern causes rails prefer on what's in mapping (skipping index
in test_report#index
).
if want live in both worlds, you'll want name other :action
.