Determining controller based on post data in Rails -
in rails application have form radio type inputs , post method. user selects 1 of these radio options , submits form. how set routing such (in routes.rb
or in other way) controller selected based on value of selected input value in post data. in routes.rb
params
hash isn't available, access data in other way?
two options come mind:
use javascript intercept submit action. on submit, read value of selected radio option, change target attribute of form url expect used , submit form.
to make javascript unobtrusive, url of target can added
data-target
attribute radio options. in way, once selected value, replace form target value ofdata-target
. benefit can generate server side , don't have hard-code value.use intermediate action. submit form action reads payload , redirects relevant controller action based on payload value.
Comments
Post a Comment