[英]Using partial with paper trail
我正在嘗試在/ events的顯示頁面中部分放置一些代碼。 當我在顯示頁面中使用該代碼時,該代碼工作正常,但是當我將其提取到部分內容時,出現“無方法錯誤”
undefined method `event' for #<ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_PaperTrail_Version:0x007f4368823a68>
版本/_version.html.erb
<% cache version do %>
<div class="feed-item">
<h4>
<%= link_to version.item.name, version.item %>
<small>
<%= version.event + "d" %> by <%= link_to User.find(version.whodunnit).username, User.find(version.whodunnit) %>
</small>
</h4>
<ul class="list-unstyled">
<% version.changeset.each do |data| %>
<li>
<strong><%= data[0].capitalize %>:</strong>
<% if data[1][0].present? %><p class="red">- <%= data[1][0] %></p><% end %>
<p class="green">+ <%= data[1][1] %></p>
</li>
<% end %>
</ul>
</div>
<% end %>
show.html.erb
<%= render :partial => '/versions/version', :object => @versions %>
事件控制器
def show
@versions = @event.versions
end
事件模型
has_paper_trail
知道我如何將我的代碼放在部分而不是將其放在show視圖中嗎? 謝謝。
編輯:我仍然收到無方法錯誤
undefined method `item' for #<ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_PaperTrail_Version:0x007f43688ee1a0>
events_controller.rb
before_action :set_event, only: [:show, :update, :destroy]
def set_event
@event = Event.find(params[:id])
end
您是否在@event
中定義了@event
變量? @event.versions
方法必須在實際的事件對象上調用。
例如
def show
@event = Event.find(1)
@versions = @event.versions
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.