Rails 部分显示最新 5 个 kase
我的应用程序设置有一些运行良好的不同部分。我在这里询问如何获得部分工作以显示 kase 模型中的最新条目,但现在我需要在部分中显示 kase 模型中的最新 5 个条目。
我已经复制了显示最近的一个部分,它在我需要的地方工作,但只显示最后一个条目,我需要更改什么才能显示最后 5 个条目?
_recent_kases.html.erb
<% if Kase.most_recentfive %>
<h4>The most recent case reference is <strong><%= Kase.most_recentfive.jobno %></strong></h4>
<% end %>
kase.rb
def self.most_recentfive
first(:order => 'id DESC')
end
谢谢,
丹尼
编辑
def self.most_recentfive
all(:order => 'id DESC', :limit=>5)
end
如果我添加上面的代码,我会收到以下错误消息:
NoMethodError in Dashboard#index
Showing app/views/kases/_recent_kases.html.erb where line #2 raised:
undefined method `jobno' for #<Array:0x105984c60>
Extracted source (around line #2):
1: <% if Kase.most_recentfive %>
2: <h4>The most recent case reference is <strong><%= Kase.most_recentfive.jobno %></strong></h4>
3: <% end %>
I have my application setup with a few different partials working well. I have asked here how to get a partial working to show the latest entry in the kase model, but now I need to show the latest 5 entries in the kase model in a partial.
I have duplicated the show most recent one partial and it's working where I need it to but only shows the last entry, what do I need to change to show the last 5?
_recent_kases.html.erb
<% if Kase.most_recentfive %>
<h4>The most recent case reference is <strong><%= Kase.most_recentfive.jobno %></strong></h4>
<% end %>
kase.rb
def self.most_recentfive
first(:order => 'id DESC')
end
Thanks,
Danny
EDIT
def self.most_recentfive
all(:order => 'id DESC', :limit=>5)
end
If I add the above code I get the following Error Message:
NoMethodError in Dashboard#index
Showing app/views/kases/_recent_kases.html.erb where line #2 raised:
undefined method `jobno' for #<Array:0x105984c60>
Extracted source (around line #2):
1: <% if Kase.most_recentfive %>
2: <h4>The most recent case reference is <strong><%= Kase.most_recentfive.jobno %></strong></h4>
3: <% end %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑添加:
然后,在您的部分中,要显示结果,您需要
EDITED TO ADD:
Then, in your partial, to display the results, you do