Rails - WillPaginate 冲突
我正在尝试对 group
拥有的 messages
进行分页。
class GroupsController < ApplicationController
...
def show
...
@message = @group.messages.paginate(:page => params[:page])
end
<% unless @group.messages.empty? %>
<table class="messages" summary="Messages from Group">
<tr>
<td class="messages">
<span class="content"><%= messages.content%></span>
<span class="timestamp">
Posted <%= time_ago_in_words(messages.created_at) %> ago.
</span>
</td>
</tr>
</table>
<%= will_paginate @messagess%>
<%end %>
但是,当我尝试打开 group#show
页面时,出现错误:undefined method 'content' for #
,但是错误给出的行是我创建新 Message
的行,它也在 group#show
页面中:
<%= f.text_area :content, :rows=>5 , :cols=>49 %>
有什么想法吗?
I'm trying to paginate the messages
a group
has.
class GroupsController < ApplicationController
...
def show
...
@message = @group.messages.paginate(:page => params[:page])
end
<% unless @group.messages.empty? %>
<table class="messages" summary="Messages from Group">
<tr>
<td class="messages">
<span class="content"><%= messages.content%></span>
<span class="timestamp">
Posted <%= time_ago_in_words(messages.created_at) %> ago.
</span>
</td>
</tr>
</table>
<%= will_paginate @messagess%>
<%end %>
But when I try to open my group#show
page, gives me the error: undefined method 'content' for #<WillPaginate::Collection:0x31a67f0>
, but the line the error gives is the line where I create a new Message
, that is in the group#show
page as well:
<%= f.text_area :content, :rows=>5 , :cols=>49 %>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要遍历消息并单独打印每一条消息。
控制器:
视图:
为了防止表单上出现错误,您需要向其传递单个消息实例。例如
You need to loop over the messages and print each one out individually.
Controller:
View:
To prevent the error on your form you will need to pass it a single instance of a message. e.g.