Added pagination for scaffolding (10 items per page) #964 [mortonda@dgrmm.net]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1067 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson
2005-04-02 09:11:17 +00:00
parent 5b36c9275d
commit 3532455404
6 changed files with 11 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
*SVN*
* Added pagination for scaffolding (10 items per page) #964 [mortonda@dgrmm.net]
* Added assert_no_cookie and fixed assert_cookie_equal to deal with non-existing cookies #979 [bitsweat]
* Fixed :overwrite_param so it doesn't delete but reject elements from @request.parameters #982 [raphinou@yahoo.com]

View File

@@ -166,7 +166,7 @@ module ActionController
:find_collection_for_pagination
def paginator_and_collection_for(collection_id, options) #:nodoc:
klass = eval options[:class_name]
klass = options[:class_name].constantize
page = @params[options[:parameter]]
count = count_collection_for_pagination(klass, options[:conditions])

View File

@@ -99,7 +99,7 @@ module ActionController
module_eval <<-"end_eval", __FILE__, __LINE__
def list#{suffix}
@#{plural_name} = #{class_name}.find_all
@#{singular_name}_pages, @#{plural_name} = paginate :#{singular_name}, :per_page => 10
render#{suffix}_scaffold "list#{suffix}"
end

View File

@@ -19,6 +19,9 @@
<% end %>
</table>
<%= link_to "Previous page", { :page => instance_variable_get("@#{@scaffold_singular_name}_pages").current.previous } if instance_variable_get("@#{@scaffold_singular_name}_pages").current.previous %>
<%= link_to "Next page", { :page => instance_variable_get("@#{@scaffold_singular_name}_pages").current.next } if instance_variable_get("@#{@scaffold_singular_name}_pages").current.next %>
<br />
<%= link_to "New #{@scaffold_singular_name}", :action => "new#{@scaffold_suffix}" %>

View File

@@ -12,7 +12,7 @@ class <%= controller_class_name %>Controller < ApplicationController
<% end -%>
def list<%= suffix %>
@<%= plural_name %> = <%= model_name %>.find_all
@<%= singular_name %>_pages, @<%= plural_name %> = paginate :<%= singular_name %>, :per_page => 10
end
def show<%= suffix %>

View File

@@ -19,6 +19,9 @@
<%% end %>
</table>
<%%= link_to "Previous page", { :page => @<%= singular_name %>_pages.current.previous } if @<%= singular_name %>_pages.current.previous %>
<%%= link_to "Next page", { :page => @<%= singular_name %>_pages.current.next } if @<%= singular_name %>_pages.current.next %>
<br />
<%%= link_to 'New <%= singular_name %>', :action => 'new<%= suffix %>' %>