首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

ruby分页有关问题

2012-10-11 
ruby分页问题controller里面:def indexrespond_to do |format|format.html {@projects Project.visible.

ruby分页问题
controller里面:
def index
  respond_to do |format|
  format.html {
  @projects = Project.visible.find(:all, :order => 'lft')
  }
  format.api {
  @offset, @limit = api_offset_and_limit
  @project_count = Project.visible.count
  @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft')
  }
  format.atom {
  projects = Project.visible.find(:all, :order => 'created_on DESC',
  :limit => Setting.feeds_limit.to_i)
  render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
  }
  end
  end
view:
<% content_for :header_tags do %>
  <%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %>
<% end %>

<div class="contextual">
  <%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add') + ' |' if User.current.allowed_to?(:add_project, nil, :global => true) %>
  <%= link_to(l(:label_issue_view_all), { :controller => 'issues' }) + ' |' if User.current.allowed_to?(:view_issues, nil, :global => true) %>
  <%= link_to(l(:label_overall_spent_time), { :controller => 'time_entries' }) + ' |' if User.current.allowed_to?(:view_time_entries, nil, :global => true) %>
  <%= link_to l(:label_overall_activity), { :controller => 'activities', :action => 'index' }%>
</div>

<h2><%=l(:label_project_plural)%></h2>

<%= render_project_hierarchy(@projects)%>

<% if User.current.logged? %>
<p style="text-align:right;">
<span class="my-project"><%= l(:label_my_projects) %></span>
</p>
<% end %>

<% other_formats_links do |f| %>
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
<% end %>

<% html_title(l(:label_project_plural)) -%>
请问应该怎么分页?这是redmine项目列表,我想把它分一下页

[解决办法]
controller里面:
-------------------------
Project.paginate :per_page => 20, :page => params[:page], :order => 'lft'



view:
增加
-----------------------------
<%= Willpaginate @projects%>

热点排行