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:

  1. 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 of data-target. benefit can generate server side , don't have hard-code value.

  2. use intermediate action. submit form action reads payload , redirects relevant controller action based on payload value.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -