public
Description: Demonstrate using will_paginate with Rails scaffolding.
Clone URL: git://github.com/mhw/crud_paginate.git
Add actions to create some fake people using the Faker gem.
mhw (author)
Fri Apr 25 03:53:26 -0700 2008
commit  80b685566b8b60ed7dfb8a16a49e8c800d370440
tree    9d17648c479a28eecfff3e111b5a87a7a0dd6c76
parent  efe902f335718dee3ca6a195cec36af654de9b7d
...
54
55
56
 
 
 
 
 
 
 
 
 
 
57
58
59
...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -54,6 +54,16 @@ class PeopleController < ApplicationController
0
     end
0
   end
0
 
0
+ # POST /people/create_fake
0
+ def create_fake
0
+ count = params[:count].to_i
0
+ count.times do
0
+ Person.fake.save
0
+ end
0
+ flash[:notice] = "Generated #{count} new people."
0
+ redirect_to people_path
0
+ end
0
+
0
   # PUT /people/1
0
   # PUT /people/1.xml
0
   def update
...
1
 
 
 
 
 
 
2
...
1
2
3
4
5
6
7
8
0
@@ -1,2 +1,8 @@
0
 class Person < ActiveRecord::Base
0
+ def self.fake
0
+ new do |p|
0
+ p.first_name = Faker::Name.first_name
0
+ p.last_name = Faker::Name.last_name
0
+ end
0
+ end
0
 end
...
20
21
22
 
 
...
20
21
22
23
24
0
@@ -20,3 +20,5 @@
0
 <br />
0
 
0
 <%= link_to 'New person', new_person_path %>
0
+or
0
+<%= link_to 'generate some fake ones', fake_people_path %>
...
25
26
27
 
28
29
30
...
64
65
66
67
68
 
...
25
26
27
28
29
30
31
...
65
66
67
 
68
69
0
@@ -25,6 +25,7 @@ Rails::Initializer.run do |config|
0
   # config.gem "bj"
0
   # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
0
   # config.gem "aws-s3", :lib => "aws/s3"
0
+ config.gem 'faker'
0
 
0
   # Only load the plugins named here, in the order given. By default, all plugins
0
   # in vendor/plugins are loaded in alphabetical order.
0
@@ -64,4 +65,4 @@ Rails::Initializer.run do |config|
0
 
0
   # Activate observers that should always be running
0
   # config.active_record.observers = :cacher, :garbage_collector
0
-end
0
\ No newline at end of file
0
+end
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 ActionController::Routing::Routes.draw do |map|
0
- map.resources :people
0
+ map.resources :people, :collection => { :fake => :get, :create_fake => :post }
0
 
0
   # The priority is based upon order of creation: first created -> highest priority.
0
 

Comments

    No one has commented yet.