我允许dispenser
使用rails中的远程链接批准dispenser_review
。数据库中的批准工作正常,但页面上链接的更新不是。
Rendered dispenser_reviews/update_approved_review.js.erb (1.6ms)
Completed 500 Internal Server Error in 22.4ms
NoMethodError - undefined method `keys' for #<Array:0x0000000e632500>:
actionpack (3.2.17) lib/action_view/renderer/partial_renderer.rb:330:in `find_partial'
分配器/ show.html.erb
<% @dispenser_reviews.all.each do |review| %>
<p id="approval<%= review.id %>"><%= render :partial => 'approve_review', locals: { review: review } %></p>
<% end %>
分配器/ _approve_review
<% if review.approved %>
<i class="icon-check-sign"></i>
<% else %>
<%= link_to "Approve", approve_dispenser_review_path(review), :remote=>true %> <%= link_to "Approve with response", "#" %>
<% end %>
dispenser_reviews_controller.rb
def approve_dispenser_review
@review = DispenserReview.find(params[:id])
@review.approved = true
@review.save
respond_to do |format|
format.js { render :action => "update_approved_review", :layout => false }
end
end
dispenser_reviews / update_approved_review.js.erb
$("#approval<%= @review.id %>").html("<%= escape_javascript(render(:partial => 'dispensers/approve_review', locals: [review: @review] )) %>")
答案 0 :(得分:1)
将dispenser_reviews/update_approved_review.js.erb
更新为
$("#approval<%= @review.id %>").html("<%= escape_javascript(render(:partial => 'dispensers/approve_review', locals: {review: @review} ))
locals: {review: @review}
而非locals:[review: @review]
。
传递哈希而不是哈希数组。