2016-01-06 190 views
1

這是我的.erb文件;Ruby on Rails將參數傳遞給partials

<% if @comment.reviewer_notes && current_user.type == "User::Reviewer"%> 
     <% @comment.reviewer_notes.each do |reviewer_note| %> 
     <?= reviewer_note.rating %> <-- this "works" ie prints out rating on screen 
     <%= render 'partials/comments/form' %> 

這是我的.erb部分;

<div class="admin-rating stars clear"> 
    <%= reviewer_note.rating %> <-- this does not work. 
</div> 

我得到的錯誤是;

未定義的方法`reviewer_rating」的#TipComment:0x007f8b38e29328>

我如何通過在reviewer_note.rating

+0

除此之外,我會改變'current_user.type == ...'來user.reviewer?並在用戶模型中添加一個實例方法。 – Mohamad

+0

閱讀[locals](http://guides.rubyonrails.org/layouts_and_rendering.html#passing-local-variables) –

回答

2
<%= render partial: 'reviewer_note_rating', locals: {reviewer_note: reviewer_note} %> 
2

您應該將其作爲變量傳遞給Partial。

<%= render 'partials/comments/form', note_rating: reviewer_note.rating %>

相關問題