我的控制器页面有问题.顺便说一下,我想执行localhost:3000/article/donat?author_id = 4,这意味着我想只查看带有author_id = 4的文章我试过这样的类型代码.
def donat
@title = "All blog entries"
if params[:author_id] == :author_id
@articles = Article.published.find_by_params(author_id)
else
@articles = Article.published
end
@articles = @articles.paginate :page => params[:page], :per_page => 20
render :template => 'home/index'
end
Run Code Online (Sandbox Code Playgroud)
它不起作用.你对这个案子有什么建议吗?
我尝试了以下代码,但它不起作用
class BlogsController < ApplicationController
def index
#@entry_pages = Paginator.new(self, Entry.count, 10, params[:page])
@entries = Entry.find(:all,
#:limit => @entry_pages.items_per_page,
#:offset => @entry_pages.current.offset,
:order => 'entries.created_at DESC',
:include => :user)
end
end
Run Code Online (Sandbox Code Playgroud)
这是博客视图
<h1>Recently updated blogs</h1>
<% @entries.each do |entry| %>
<p>
<%= link_to entry.user.username, entries_url(:user_id => entry.user) %><br />
'<%= entry.title %>' was posted <%= time_ago_in_words(entry.created_at) %> ago
</p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我希望这些项目像这样分页:
<< [1][2][3] >>
Run Code Online (Sandbox Code Playgroud)