Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Can you try rewriting this route:</p> <pre><code>match '/currencies/', to: 'converter#show', via: [:post] </code></pre> <p>to:</p> <pre><code>match '/currencies/:from-:to', to: 'converter#show', via: [:post] </code></pre> <p>In this case requests to (for example) /currencies/usd-eur will be routed to converter#show and you will be able to access the currencies in the controller action using params[from] and params[:to].</p> <p><strong>UPDATE:</strong></p> <ol> <li>There was an error in javascript code:</li> </ol> <p>This code should work as you expected:</p> <pre><code>&lt;script&gt; $(document).ready(function(){ $("#currency_form").submit(function(e){ var from = $('#convertor_from_currency').val(); var to = $('#convertor_to_currency').val(); var url_end = from + "-" + to; var url = $('#currency_form').attr('action') + '/' + url_end; $.post(url, $('#currency_form').serialize(), function(data){alert('success');}); alert(url); e.preventDefault(); return false; }); }); &lt;/script&gt; </code></pre> <p>You should not call submit on form as long as you are inside submit handler. Instead, you should use $.post(...) to submit the form data. Form data can be serialized as in my example to be sent with the $.post(). You should have added "});" before closing tag.</p> <ol> <li><p>One of routing configurations that should work for you:</p> <p>match '/currencies/' => 'converter#index', as: :converter match '/currencies/:from-:to' => 'converter#show', via: [:post]</p> <p>your form should use converter_path helper as the action url. And the JS code should submit the form to /currencies/:from-:to.</p></li> <li><p>You need to update the form in the view to:</p> {:id => "currency_form"}, :url => converter_path do |f| %></li> <li><p>You can use this sample code in your controller to ensure that the form is submitted correctly:</p> <p>def show @amount = params[:convertor][:amount] @from_cur = params[:convertor][:from_currency] @to_cur = params[:convertor][:to_currency]</p> <p>#@result = ConverterHelper.show(@from_cur, @to_cur, @amount) render text: "text" end</p></li> </ol> <p>You can uncomment the line and remove render once you see that the form is correctly processed on the server.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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