我試圖解決這個問題一段時間沒有結果。 我想傳遞變量並使用CoffeeScript中的軌道4將渲染加載到div中。 (我正在使用SpreeCommerce平臺)。如何在Ruby on Rails 4中通過CoffeeScript渲染4
視圖:
<%= link_to taxonomy.name,root_path+'t/'+tid, {class: "uno", remote: true} %>
控制器:
respond_to do |format|
format.html
format.js # menu.js.coffee.erb
end
menu.js.erb.coffee:
$('div#productos').html("<%= escape_javascript(render :partial => /shared/products) %>")
我想LOA d頁面'_products.erb.html'和部分處理我給它的變量。只要我知道,查看和控制器是好的,問題是在menu.js.erb.coffee
任何幫助將被認爲是!
補充:
我修改了擴展.js.coffee.erb。當我嘗試運行應用程序,它讓我看到:
「未定義的方法`呈現」爲#<#:0xa70317c>」
我使用<%= raw escape_javascript(render :partial =>...
幾乎總是 「渲染」 tryied方法給我問題。
NEW INFO:
我添加gem 'coffee-script'
到Gemfile中(然後 'bundle install
')。 現在,當我點擊link_to時,它會將文本顯示爲一個文本,而不是加載「部分」... HTML中的任何建議,請將其顯示爲HTML <%= escape_javascript(render:partial =>/shared/products)%> ?
貢獻嘗試做 '<%= escape_javascript(render:partial => /shared/products).html_safe%>' – davidicus
您是否解決了這個問題? – ashes999
我使用.js工作,並將該文件放到與我的視圖文件相同的文件夾中。 –