将范围与视图部分结合使用
我一直在使用范围来提供一些信息来显示已完成且 24 小时前的待办事项
scope :completed, joins(:user).where(:todos => { :complete => true })
scope :logged, completed.where("todos.updated_at <= ?", 1.day.ago)
使用常规待办事项部分
<%= render @user.todos.logged =>
但是我想在不同的部分 _logged.html.erb 中显示这些记录的项目。我只是无法找出将范围结果传递给特定部分的正确方法。
谢谢
I have been using a scope to present some information to show todos that have been completed and are 24 hours old
scope :completed, joins(:user).where(:todos => { :complete => true })
scope :logged, completed.where("todos.updated_at <= ?", 1.day.ago)
Using the regular todo partial
<%= render @user.todos.logged =>
However I want to present those logged items in a different partial _logged.html.erb. I just can't figure out the proper way to pass scope results to a specific partial.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,如果你想为每个项目渲染部分内容,你可以这样做:
或者如果你想将整个数组传递给一个实例,那么你可以这样做
在这两种情况下我猜你的对象将被称为
logged
。假设您的部分包含您想要为每个项目渲染的
<%=logging.title %>
,因此您可以使用第一个版本。Well, if you want to render partial for each item, yo can do:
Or if you want to pass the whole array to one instance then you can do
In both cases I guess your object will be called
logged
.Assuming that your partial contains
<%= logged.title %>
you want to render for each item, so you can use the first version.首先,为了保持我的良心,我要说的是,将模型代码传递给你的视图从来都不是一个好主意。但如果你坚持:
First, to keep my conscience clean, let me say that that passing model code to your views is never a good idea. But if you insist :