使用脚本自动更改动态提取的货币

时间:2015-07-17 00:00:09

标签: javascript ruby-on-rails

我有经销商计划,但货币只有英镑,美元,日元和欧元。

我可以设置自己的价格但是我想在用户页面上显示货币为泰铢。

产品和价格在轨道上的ruby上动态提取,我可以访问代码,但我不能将货币更改为泰铢。

我的问题是,是否可以使用脚本,因此当页面加载时,它会用我想要的货币替换当前值。

即如果我的价值为1.00美元,脚本将用฿替换$并且用3.00乘以33,因此用户将看到฿33而不是$ 1.00。

以下是我可以编辑的代码示例:

<script type='text/javascript'>
// <[CDATA[
// Populate some hashes in the js context:
var dual_core = new Array();
<% dual_core.each do |dc| %>
dual_core["<%= dc.specific_type %>-<%= dc.base_renewal_period %>"] = new Array();
dual_core["<%= dc.specific_type %>-<%= dc.base_renewal_period %>"]["specific_type"] = "<%= dc.specific_type %>";
dual_core["<%= dc.specific_type %>-<%= dc.base_renewal_period %>"]["base_renewal_period"] = "<%= dc.base_renewal_period %>";
dual_core["<%= dc.specific_type %>-<%= dc.base_renewal_period %>"]["unit_price"] = "<%= dc.unit_price %>";
dual_core["<%= dc.specific_type %>-<%= dc.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(dc.unit_price) %>";
dual_core["<%= dc.specific_type %>-<%= dc.base_renewal_period %>"]["display_price"] = "<%= billing.price(dc.unit_price, :use_tax_prefs) %>";
<% end %>
var quad_core = new Array();
<% quad_core.each do |qc| %>
quad_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"] = new Array();
quad_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["specific_type"] = "<%= qc.specific_type %>";
quad_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["base_renewal_period"] = "<%= qc.base_renewal_period %>";
quad_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["unit_price"] = "<%= qc.unit_price %>";
quad_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(qc.unit_price) %>";
quad_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["display_price"] = "<%= billing.price(qc.unit_price, :use_tax_prefs) %>";
<% end %>
var quad_core_bd = new Array();
<% quad_core_bd.each do |qc| %>
quad_core_bd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"] = new Array();
quad_core_bd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["specific_type"] = "<%= qc.specific_type %>";
quad_core_bd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["base_renewal_period"] = "<%= qc.base_renewal_period %>";
quad_core_bd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["unit_price"] = "<%= qc.unit_price %>";
quad_core_bd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(qc.unit_price) %>";
quad_core_bd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["display_price"] = "<%= billing.price(qc.unit_price, :use_tax_prefs) %>";
<% end %>
var octo_core = new Array();
<% octo_core.each do |qc| %>
octo_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"] = new Array();
octo_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["specific_type"] = "<%= qc.specific_type %>";
octo_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["base_renewal_period"] = "<%= qc.base_renewal_period %>";
octo_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["unit_price"] = "<%= qc.unit_price %>";
octo_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(qc.unit_price) %>";
octo_core["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["display_price"] = "<%= billing.price(qc.unit_price, :use_tax_prefs) %>";
<% end %>
var octo_core_fd = new Array();
<% octo_core_fd.each do |qc| %>
octo_core_fd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"] = new Array();
octo_core_fd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["specific_type"] = "<%= qc.specific_type %>";
octo_core_fd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["base_renewal_period"] = "<%= qc.base_renewal_period %>";
octo_core_fd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["unit_price"] = "<%= qc.unit_price %>";
octo_core_fd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(qc.unit_price) %>";
octo_core_fd["<%= qc.specific_type %>-<%= qc.base_renewal_period %>"]["display_price"] = "<%= billing.price(qc.unit_price, :use_tax_prefs) %>";
<% end %>
var cpanel = new Array();
<% cpanel.each do |cp| %>
cpanel["<%= cp.specific_type %>-<%= cp.base_renewal_period %>"] = new Array();
cpanel["<%= cp.specific_type %>-<%= cp.base_renewal_period %>"]["specific_type"] = "<%= cp.specific_type %>";
cpanel["<%= cp.specific_type %>-<%= cp.base_renewal_period %>"]["base_renewal_period"] = "<%= cp.base_renewal_period %>";
cpanel["<%= cp.specific_type %>-<%= cp.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(cp.unit_price) %>";
cpanel["<%= cp.specific_type %>-<%= cp.base_renewal_period %>"]["display_price"] = "<%= billing.price(cp.unit_price, :use_tax_prefs) %>";
<% end %>
var backup = new Array();
<% backup.each do |bk| %>
backup["<%= bk.specific_type %>-<%= bk.base_renewal_period %>"] = new Array();
backup["<%= bk.specific_type %>-<%= bk.base_renewal_period %>"]["specific_type"] = "<%= bk.specific_type %>";
backup["<%= bk.specific_type %>-<%= bk.base_renewal_period %>"]["base_renewal_period"] = "<%= bk.base_renewal_period %>";
backup["<%= bk.specific_type %>-<%= bk.base_renewal_period %>"]["quoted_unit_price"] = "<%= billing.price(bk.unit_price) %>";
backup["<%= bk.specific_type %>-<%= bk.base_renewal_period %>"]["display_price"] = "<%= billing.price(bk.unit_price, :use_tax_prefs) %>";
<% end %>
// ]]>
</script>
<!--
<script type='text/javascript' src='<%= url_prefix %>ds.js'></script>
-->
<!-- include the template ds-js.rhtml -->
<% included_content_result = include_common_template("ds-js.rhtml", "@included_content_out_js") %>
<%= included_content_result %>
<div class='container' id='t-dedicated-servers'>
<h2 id='effective-title'>Dedicated Servers</h2>
<p>
Our range of Dedicated Servers provide either Dual or Quad core processors, include
 unlimited bandwidth and are perfect for busy websites or hosting multiple websites on one machine.
</p>
<p>
Choose from Linux CentOS or Windows Web Server 2008. All servers are setup with
 your choice of operating system in about 30 minutes by our automated system.
</p>
<% @os_to_name = { "linux" => "Linux (CentOS)", "windows" => "Windows Server 2008 Web Edition", "windows_se" => "Windows Server 2008 Standard Edition"} %>
<form accept-charset='utf-8' method='post' action='basket' id='order-form'>
<% if no_upsell? %><input type='hidden' name='no-upsell' value='1'/><% end %>
<table style='border: 1'>
<tbody>
<tr>
<% if dual_core_for_sale %>

 <% @core_type = "2c" %>
 <!-- include the template ds-common.rhtml -->
 <% included_content_result = include_common_template("ds-common.rhtml", "@included_content_out_two") %>
 <%= included_content_result %>

<% end %>
<% if quad_core_for_sale %>
 <% if os_list['4c'].size > 0 %>

  <% @core_type = "4c" %>
  <!-- include the template ds-common.rhtml -->
  <% included_content_result = include_common_template("ds-common.rhtml", "@included_content_out_four") %>
  <%= included_content_result %>

 <% end # os_list[4c].size > 0 %>
 <!-- Quad core large disk -->
 <% if quad_core_large_disk_for_sale %>

  <% @core_type = "4c_bd" %>
  <!-- include the template ds-common.rhtml -->
  <% included_content_result = include_common_template("ds-common.rhtml", "@included_content_out_four_b") %>
  <%= included_content_result %>

 <% end # quad_core_large_disk_for_sale %>
<% end %>
</tr>
<tr>
<% if octo_core_for_sale %>
 <% if os_list['8c_bd'].size > 0 %>

  <% @core_type = "8c_bd" %>
  <!-- include the template ds-common.rhtml -->
  <% included_content_result = include_common_template("ds-common.rhtml", "@included_content_out_eight") %>
  <%= included_content_result %>

 <% end # os_list['8c'].size > 0 %>
 <!-- Octo (2xQuad) core fast disk -->
 <% if octo_core_fd_for_sale %>

  <% @core_type = "8c_fd" %>
  <!-- include the template ds-common.rhtml -->
  <% included_content_result = include_common_template("ds-common.rhtml", "@included_content_out_eight_b") %>
  <%= included_content_result %>

 <% end # octo_core_fd_for_sale %>

<% end %>
</tr>


</tbody>
</table>
<% if free_products.size > 0 %>
<p>
If you order a Dedicated Server you will be entitled to one free registration for the minimum period of a domain of one of the following types:<br />
<% free_products.each_key do |fp| %>
<%= free_products[fp] %><br />
<% end %>
</p>
<% end %>
<p><input type='submit' value='Add to Basket' onclick='javascript: if(!get_selected_period()) { alert("Please choose a price and payment frequency");return false; } else { return true; };'/></p>
</form>
<% unless basket.nil? or basket.empty? or no_upsell? %>
<p><a href='basket?add-no-product=ds'>No thank you, please continue with my order ....</a></p>
<% end %>
<% if not billing.tax_applies? %>
<% elsif billing.include_tax? %>
    <p>* Includes <%= billing.tax_name %></p>
<% else %>
    <p>* Excluding <%= billing.tax_name %></p>
<% end %>
</div>

<%
=begin advice %>

    This section is completely ignored and can safely be removed.

<%
=end advice %>

我希望我已经解释得足以让你明白了。

提前感谢您阅读或帮助我。

1 个答案:

答案 0 :(得分:0)

我认为您应该使用此soap webservice转换货币。这可以使用服务器上的服务器端脚本或客户端的JavaScript soap client library来完成。