简体   繁体   English

混合Rails和javascript代码时的报价问题

[英]quotation issues when mixing rails and javascript code

I'm trying to putting Rails and javascript code togetherto make a query string, here is the code: 我正在尝试将Rails和javascript代码放在一起以创建查询字符串,这是代码:

link_to('CSV', '#', {:onclick => 'location.href="' + url_for(:controller => 'balances', :action => 'pc_form', :term => @fiscal_master.term, :format => 'csv') + '&month_index=" + \
jQuery("#month_index").val(); + "&dept_code=" + jQuery("#dept_code").val();', :id => "pc_csv", :class => 'dl_button' })

and it renders: 它呈现:

<a href="#" class="dl_button" id="pc_csv" onclick="location.href=&quot;/balances/pc_form?format=csv&amp;term=10&amp;month_index=&quot; + jQuery(&quot;#month_index&quot;).val(); + &quot;&amp;dept_code=&quot; + jQuery(&quot;#dept_code&quot;).val();">CSV</a>

When I click the button, the second query "dept_code" doesn't show up. 当我单击按钮时,第二个查询“ dept_code”没有出现。 I'm guessing it's the quotation issue, but I don't know how to make it correct. 我猜这是报价问题,但我不知道如何使其正确。

Try 尝试

link_to('CSV', '#', {:onclick => 'location.href="' + url_for(:controller => \'balances\', :action => \'pc_form\', :term => @fiscal_master.term, :format => \'csv\') + '&month_index=" + \
jQuery("#month_index").val(); + "&dept_code=" + jQuery("#dept_code").val();', :id => "pc_csv", :class => 'dl_button' })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM