Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating dynamic url based on form inputs
    primarykey
    data
    text
    <p>I need to generate a url based on two drop-down inputs, from currency and two currency such that when a user clicks submit button, the url generated should look like <code>http://localhost:3000/currencies/usd-eur</code> when form currency is usd and to_currency is eur for example. </p> <p>Here's my views(index.html.erb) </p> <pre><code> &lt;%= semantic_form_for :calculator, :url =&gt; {:controller =&gt; "conversions", :action =&gt; "calculate" } do |f| %&gt; &lt;p&gt;&lt;%= f.label :amount %&gt; &lt;%= f.text_field :amount %&gt;&lt;/p&gt; &lt;p&gt;&lt;%= f.label :from_currency %&gt; &lt;%= select :calculator, :from_currency, Choices['from_currency'] %&gt;&lt;/p&gt; &lt;/p&gt;&lt;%= f.label :to_currency %&gt; &lt;%= select :calculator, :to_currency, Choices['to_currency'] %&gt;&lt;/p&gt; &lt;p&gt;&lt;%= f.submit "Calculate" %&gt;&lt;/p&gt; &lt;%= end %&gt; </code></pre> <p>routes.rb</p> <pre><code>match 'currencies', to: 'conversions#index', via: :get match 'currencies/convert', to: 'conversions#calculate', as: :calculate, via: :post </code></pre> <p>controller(conversions_controller.rb)</p> <pre><code>def index end def calculate @amount = params[:calculator][:amount] @from_cur = params[:calculator][:from_currency] @to_cur = params[:calculator][:to_currency] @result = ConversionsHelper.calculate(@from_cur, @to_cur, @amount) end </code></pre> <p>I don't have any models for that matter since I get my data from google API hence I could be going outside the boundaries of RESFFUL conventions. A detailed answer would be appreciated. Thanks. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload