Ruby 关于 Rails 将参数传递给部分
Ruby on Rails passing parameters to partials
这是我的 .erb 文件;
<% 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>
我得到的错误是;
undefined method `reviewer_rating' for #TipComment:0x007f8b38e29328>
如何传入reviewer_note.rating
?
您应该将其作为变量传递给 Partial。
<%= render 'partials/comments/form', note_rating: reviewer_note.rating %>
<%= render partial: 'reviewer_note_rating', locals: {reviewer_note: reviewer_note} %>
这是我的 .erb 文件;
<% 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>
我得到的错误是;
undefined method `reviewer_rating' for #TipComment:0x007f8b38e29328>
如何传入reviewer_note.rating
?
您应该将其作为变量传递给 Partial。
<%= render 'partials/comments/form', note_rating: reviewer_note.rating %>
<%= render partial: 'reviewer_note_rating', locals: {reviewer_note: reviewer_note} %>