简体   繁体   中英

Ruby on Rails passing parameters to partials

This is my .erb file;

<% 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' %>

this is my .erb partial;

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

The error I get is;

undefined method `reviewer_rating' for #TipComment:0x007f8b38e29328>

How do I pass in reviewer_note.rating ?

您应该将其作为变量传递给Partial。

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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