我有一個控制器donations_controller
渲染中軌與一些變量視圖
class DonationsController < ApplicationController
def index
donation = Donation.find_by_id(1).donation
donation_percent = donation.to_f/50*100
end
end
和視圖donations/_index.html.erb
<div class="progress">
<div class="bar" style="width:<%[email protected]_percent%>%;"></div>
</div>
<p>Donated: €<%[email protected]%></p>
當我嘗試呈現它的任何其他視圖內(例如,static/index.html.erb
- 我的網站主頁),它沒有變量就被渲染。這裏是我使用的代碼
...
<%=render partial: "donations/index", donation: @donation, donation_percent: @donation_percent%>
...
我該怎麼做才能渲染變量?謝謝。
你甲肝e '<%= yield %>' 在您的佈局? –
當然,我有,但它怎麼能幫助我? – enjaku