Ruby on rails 给班级编页码
请帮我对这个方法进行分页 我的方法是这个 控制器Ruby on rails 给班级编页码,ruby-on-rails,Ruby On Rails,请帮我对这个方法进行分页 我的方法是这个 控制器 def show @topic = Topic.find(params[:id]) @posts = @topic.posts.find(:all ,:order=> 'id') end # 观点 %div{:style=>"margin: 0 auto;"} %table.sortable.style2{:cellpadding=>5} %thead %tr %td{:wid
def show
@topic = Topic.find(params[:id])
@posts = @topic.posts.find(:all ,:order=> 'id')
end
#
观点
%div{:style=>"margin: 0 auto;"}
%table.sortable.style2{:cellpadding=>5}
%thead
%tr
%td{:width => "25%",:align => "center",:style => "font-weight: bold;"}Posted By
%td{:width => "75%",:style => "font-weight: bold;"}Comments
%tbody
- for post in @posts
%tr
%td{:align => "center"}
 
%div{:width=>"5px" , :style=>"border: 1px solid rgb(232, 232, 232);background-color: rgb(248, 248, 248);width: 60px; height:60px;" }
- if post.posted_by.image
= image_tag(post.posted_by.image.public_filename(),:width => "60px", :height => "60px",:align=>"center")
%div{:style => "font-weight: bold; font-style: italic;"}
= post.posted_by ? post.posted_by.firstname : "<em>Unknown User</em>"
%br
%div{:style => "font-style: italic;"}
Posted on
= post.created_at.strftime('%d of %B %Y ')
= post.created_at.strftime('at %H:%M')
%td{:valign => "top"}
=post.body
#
%div{:style=>“边距:0自动;”}
%table.sortable.style2{:cellpadding=>5}
%泰德
%tr
%td{:width=>“25%”,:align=>“center”,:style=>“font-weight:bold;”}发布人
%td{:width=>“75%”,:style=>“font-weight:bold;”}注释
%t车身
-对于@posts中的post
%tr
%td{:align=>“中心”}
 
%div{:width=>“5px”,“style=>”边框:1px实心rgb(232,232,232);背景色:rgb(248,248,248);宽度:60px;高度:60px;“}
-如果post.post_by.image
=image_标记(post.posted_by.image.public_filename(),:width=>“60px”,:height=>“60px”,:align=>“center”)
%div{:style=>“字体大小:粗体;字体样式:斜体;”}
=post.posted\u by?post.posted_by.firstname:“未知用户”
%溴
%div{:style=>“字体样式:斜体;”}
张贴在
=post.created_在.strftime(“%d,共%B%Y”)
=post.created_在.strftime('at%H:%M')
%td{:valign=>“top”}
=post.body
分页实际上是米斯拉夫的简单操作。阅读文件中的,和示例。这个例子几乎完全涵盖了你的目标
对于您的场景,您希望从编辑Post
model类开始。指定每页要查看的文章数量:
class Post < ActiveRecord::Base
cattr_reader :per_page
@@per_page = 10
end
然后,在您想要显示页面链接的视图中,只需执行以下操作:
= will_paginate @posts
你到底有什么问题?这是毫无疑问的。
= will_paginate @posts