我遇到了这个问题:
#Array:0x00007f3e929cc430 的未定义方法“model_name”
{ count: collection.count(:all),
page: params[vars[:page_param]||Pagy::VARS[:page_param]],
item_path: "activerecord.models.#{collection.model_name.i18n_key}" }.merge!(vars)
end
这是我的data_controller.rb:
def index
@pagy, @datas = pagy(Data.active_only.where(data_location: @location).sort_by(&:id))
end
这是我的 application_controller.rb
def pagy_get_vars(collection, vars)
{ count: collection.count(:all),
page: params[vars[:page_param]||Pagy::VARS[:page_param]],
item_path: "activerecord.models.#{collection.model_name.i18n_key}" }.merge!(vars)
end
最后是我的观点
<div>
<table id="tablestock" class="table_content table">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th class="sorting_disabled">Location</th>
<th class="sorting_disabled">Name</th>
</tr>
</thead>
<tbody>
<% @datas.each do |data| %>
<tr data-link="<%= data_path(data) %>">
<td><%= data.id %></td>
<td><%= data.created_at.strftime('%d %b %Y') rescue ("<b style='color:red; font-size:16px;'>ERROR</b>".html_safe)%></td>
<td><%=data.data_location.location if data.location_id? %></td>
<td><%= data.data_name.name if data.name_id? %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="justify">
<%= pagy_nav(@pagy).html_safe if @datas.present? %>
</div>
</div>