aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/pagination.rb2
-rw-r--r--actionpack/lib/action_controller/scaffolding.rb2
-rw-r--r--actionpack/lib/action_controller/templates/scaffolds/list.rhtml3
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb2
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml3
6 files changed, 11 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index d0cc7b35bf..4fd2ceddba 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/pagination.rb b/actionpack/lib/action_controller/pagination.rb
index b9fa01df9f..fd890c53e0 100644
--- a/actionpack/lib/action_controller/pagination.rb
+++ b/actionpack/lib/action_controller/pagination.rb
@@ -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])
diff --git a/actionpack/lib/action_controller/scaffolding.rb b/actionpack/lib/action_controller/scaffolding.rb
index bf2e35f3f7..4faa23cdf3 100644
--- a/actionpack/lib/action_controller/scaffolding.rb
+++ b/actionpack/lib/action_controller/scaffolding.rb
@@ -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
diff --git a/actionpack/lib/action_controller/templates/scaffolds/list.rhtml b/actionpack/lib/action_controller/templates/scaffolds/list.rhtml
index 33af7079b2..df1b7f8e4c 100644
--- a/actionpack/lib/action_controller/templates/scaffolds/list.rhtml
+++ b/actionpack/lib/action_controller/templates/scaffolds/list.rhtml
@@ -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}" %>
diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
index b3190918bd..4959674976 100644
--- a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
+++ b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb
@@ -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 %>
diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml b/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml
index 0ca1d1c97e..f30772b41b 100644
--- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml
+++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml
@@ -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 %>' %>