mardi 11 octobre 2016

Using if statement with country_select in to display div rails App

My users have to select a country via country_select gem and if they select "US" a divwill be displayed. I'm using the if statementbelow to display it.

<%if :country == "US" %>

<div class="col-md-5">

 <p>delivery cost</p>

 <p><%= @del_cost_euro %> </p>

 <p><%= @cart.total_price_usd %></p>

 <p><%= @cart.total_price_usd + @del_cost_euro %>

</div>

<% end %>

here is the part were the f.country_selectis

<div class="form-group">
    <div class="col-md-5">
        <%= f.label :country %>
        <%= f.country_select :country, { priority_countries: [ "US", "DE", "ES", "PT" ]}, { class: "form-control" }%>
    </div>

</div>  

The thing is that the country doesn't go to the database until after the User have checked out the order. So it is basically not possible for the if statement to know if the user has selected "US" or another country.

Is it possible to make this somehow dynamic so it gets updated on the fly?

any help would be nice.

Aucun commentaire:

Enregistrer un commentaire