crudify 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -2
- data/Gemfile.lock +57 -28
- data/README.md +121 -3
- data/Rakefile +3 -4
- data/crudify.gemspec +5 -2
- data/lib/crudify.rb +5 -1
- data/lib/crudify/base.rb +8 -7
- data/lib/crudify/class_methods.rb +35 -21
- data/lib/crudify/hook_methods.rb +30 -33
- data/lib/crudify/version.rb +1 -1
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/admin/peanut_butters_controller.rb +5 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/jellies_controller.rb +7 -0
- data/test/dummy/app/models/jelly.rb +9 -0
- data/test/dummy/app/models/peanut_butter.rb +8 -0
- data/test/dummy/app/views/admin/peanut_butters/_fields.html.erb +4 -0
- data/test/dummy/app/views/admin/peanut_butters/edit.html.erb +11 -0
- data/test/dummy/app/views/admin/peanut_butters/index.html.erb +23 -0
- data/test/dummy/app/views/admin/peanut_butters/new.html.erb +11 -0
- data/test/dummy/app/views/admin/peanut_butters/show.html.erb +14 -0
- data/test/dummy/app/views/jellies/_fields.html.erb +8 -0
- data/test/dummy/app/views/jellies/edit.html.erb +11 -0
- data/test/dummy/app/views/jellies/index.html.erb +23 -0
- data/test/dummy/app/views/jellies/new.html.erb +11 -0
- data/test/dummy/app/views/jellies/show.html.erb +15 -0
- data/test/dummy/app/views/layouts/application.html.erb +72 -0
- data/test/dummy/app/views/shared/_error_messages.html.erb +9 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +38 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/green_eggs_and_spam.rb +2 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/routes.rb +11 -0
- data/test/dummy/db/migrate/20110223073415_create_jellies.rb +13 -0
- data/test/dummy/db/migrate/20110223073427_create_peanut_butters.rb +12 -0
- data/test/dummy/db/schema.rb +28 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/{log/development.log → test/dummy/public/favicon.ico} +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/index.html +239 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +191 -0
- data/test/dummy/public/stylesheets/styles.css +126 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/jellies_controller_test.rb +55 -0
- data/test/helper.rb +42 -31
- data/test/integration/demo_test.rb +79 -0
- data/test/{test_controller.rb → unit/crudify_test.rb} +17 -17
- metadata +149 -13
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,45 +1,62 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
crudify (0.0.
|
4
|
+
crudify (0.1.0.beta)
|
5
5
|
meta_search (>= 1.0.1)
|
6
6
|
rails (>= 3.0.0)
|
7
|
+
will_paginate (>= 2.3.15)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
10
11
|
specs:
|
11
12
|
abstract (1.0.0)
|
12
|
-
actionmailer (3.0.
|
13
|
-
actionpack (= 3.0.
|
14
|
-
mail (~> 2.2.
|
15
|
-
actionpack (3.0.
|
16
|
-
activemodel (= 3.0.
|
17
|
-
activesupport (= 3.0.
|
13
|
+
actionmailer (3.0.5)
|
14
|
+
actionpack (= 3.0.5)
|
15
|
+
mail (~> 2.2.15)
|
16
|
+
actionpack (3.0.5)
|
17
|
+
activemodel (= 3.0.5)
|
18
|
+
activesupport (= 3.0.5)
|
18
19
|
builder (~> 2.1.2)
|
19
20
|
erubis (~> 2.6.6)
|
20
21
|
i18n (~> 0.4)
|
21
22
|
rack (~> 1.2.1)
|
22
23
|
rack-mount (~> 0.6.13)
|
23
|
-
rack-test (~> 0.5.
|
24
|
+
rack-test (~> 0.5.7)
|
24
25
|
tzinfo (~> 0.3.23)
|
25
|
-
activemodel (3.0.
|
26
|
-
activesupport (= 3.0.
|
26
|
+
activemodel (3.0.5)
|
27
|
+
activesupport (= 3.0.5)
|
27
28
|
builder (~> 2.1.2)
|
28
29
|
i18n (~> 0.4)
|
29
|
-
activerecord (3.0.
|
30
|
-
activemodel (= 3.0.
|
31
|
-
activesupport (= 3.0.
|
30
|
+
activerecord (3.0.5)
|
31
|
+
activemodel (= 3.0.5)
|
32
|
+
activesupport (= 3.0.5)
|
32
33
|
arel (~> 2.0.2)
|
33
34
|
tzinfo (~> 0.3.23)
|
34
|
-
activeresource (3.0.
|
35
|
-
activemodel (= 3.0.
|
36
|
-
activesupport (= 3.0.
|
37
|
-
activesupport (3.0.
|
38
|
-
arel (2.0.
|
35
|
+
activeresource (3.0.5)
|
36
|
+
activemodel (= 3.0.5)
|
37
|
+
activesupport (= 3.0.5)
|
38
|
+
activesupport (3.0.5)
|
39
|
+
arel (2.0.9)
|
39
40
|
builder (2.1.2)
|
41
|
+
capybara (0.4.1.2)
|
42
|
+
celerity (>= 0.7.9)
|
43
|
+
culerity (>= 0.2.4)
|
44
|
+
mime-types (>= 1.16)
|
45
|
+
nokogiri (>= 1.3.3)
|
46
|
+
rack (>= 1.0.0)
|
47
|
+
rack-test (>= 0.5.4)
|
48
|
+
selenium-webdriver (>= 0.0.27)
|
49
|
+
xpath (~> 0.1.3)
|
50
|
+
celerity (0.8.8)
|
51
|
+
childprocess (0.1.7)
|
52
|
+
ffi (~> 0.6.3)
|
53
|
+
culerity (0.2.15)
|
40
54
|
erubis (2.6.6)
|
41
55
|
abstract (>= 1.0.0)
|
56
|
+
ffi (0.6.3)
|
57
|
+
rake (>= 0.8.7)
|
42
58
|
i18n (0.5.0)
|
59
|
+
json_pure (1.5.1)
|
43
60
|
mail (2.2.15)
|
44
61
|
activesupport (>= 2.3.6)
|
45
62
|
i18n (>= 0.4.0)
|
@@ -51,26 +68,33 @@ GEM
|
|
51
68
|
activesupport (~> 3.0.2)
|
52
69
|
arel (~> 2.0.2)
|
53
70
|
mime-types (1.16)
|
71
|
+
nokogiri (1.4.4)
|
54
72
|
polyglot (0.3.1)
|
55
73
|
rack (1.2.1)
|
56
74
|
rack-mount (0.6.13)
|
57
75
|
rack (>= 1.0.0)
|
58
76
|
rack-test (0.5.7)
|
59
77
|
rack (>= 1.0)
|
60
|
-
rails (3.0.
|
61
|
-
actionmailer (= 3.0.
|
62
|
-
actionpack (= 3.0.
|
63
|
-
activerecord (= 3.0.
|
64
|
-
activeresource (= 3.0.
|
65
|
-
activesupport (= 3.0.
|
78
|
+
rails (3.0.5)
|
79
|
+
actionmailer (= 3.0.5)
|
80
|
+
actionpack (= 3.0.5)
|
81
|
+
activerecord (= 3.0.5)
|
82
|
+
activeresource (= 3.0.5)
|
83
|
+
activesupport (= 3.0.5)
|
66
84
|
bundler (~> 1.0)
|
67
|
-
railties (= 3.0.
|
68
|
-
railties (3.0.
|
69
|
-
actionpack (= 3.0.
|
70
|
-
activesupport (= 3.0.
|
85
|
+
railties (= 3.0.5)
|
86
|
+
railties (3.0.5)
|
87
|
+
actionpack (= 3.0.5)
|
88
|
+
activesupport (= 3.0.5)
|
71
89
|
rake (>= 0.8.7)
|
72
90
|
thor (~> 0.14.4)
|
73
91
|
rake (0.8.7)
|
92
|
+
rubyzip (0.9.4)
|
93
|
+
selenium-webdriver (0.1.3)
|
94
|
+
childprocess (~> 0.1.5)
|
95
|
+
ffi (~> 0.6.3)
|
96
|
+
json_pure
|
97
|
+
rubyzip
|
74
98
|
shoulda (2.11.3)
|
75
99
|
sqlite3 (1.3.3)
|
76
100
|
sqlite3-ruby (1.3.3)
|
@@ -79,11 +103,16 @@ GEM
|
|
79
103
|
treetop (1.4.9)
|
80
104
|
polyglot (>= 0.3.1)
|
81
105
|
tzinfo (0.3.24)
|
106
|
+
will_paginate (2.3.15)
|
107
|
+
xpath (0.1.3)
|
108
|
+
nokogiri (~> 1.3)
|
82
109
|
|
83
110
|
PLATFORMS
|
84
111
|
ruby
|
85
112
|
|
86
113
|
DEPENDENCIES
|
114
|
+
capybara (>= 0.4.1)
|
87
115
|
crudify!
|
116
|
+
selenium-webdriver (>= 0.1.3)
|
88
117
|
shoulda (>= 2.11.3)
|
89
118
|
sqlite3-ruby (>= 1.3.3)
|
data/README.md
CHANGED
@@ -1,14 +1,132 @@
|
|
1
1
|
Crudify
|
2
|
-
|
2
|
+
=======
|
3
|
+
|
4
|
+
A dynamic resource controller for Rails 3 that keeps your controllers nice and skinny.
|
3
5
|
|
4
|
-
|
6
|
+
Crudify was shamlessly robbed from [refinerycms](https://github.com/resolve/refinerycms/blob/master/core/lib/refinery/crud.rb)'s internals and customized for use in other projects. Much credit and many thanks to the guys at [resolve digital](http://resolvedigital.com/) for all their hard work on the [refinery cms project](http://resolvedigital.com/development/refinery%C2%A0cms). Keep it up!
|
5
7
|
|
6
8
|
|
7
9
|
Usage
|
8
10
|
-----
|
9
11
|
|
10
|
-
|
12
|
+
In its most basic form, crudify is designed to be use like this:
|
13
|
+
|
14
|
+
class JelliesController < ApplicationController
|
15
|
+
crudify :jelly
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
Ok, so what does it do? The short answer; _everything_ that you'd want it to. In more detail, crudify turns your controller into a full-fledged CRUD controller with `index`, `new`, `create`, `show`, `edit`, `update`, and `destroy`. But wait, there's more! Inside each of these standard methods are several _hook methods_ designed to make customizing your controllers even easier that over-riding crudify's methods. Over-riding; say what? ...
|
20
|
+
|
21
|
+
Say you want to customize an action that's being defined by crudify, simply over-ride it!
|
22
|
+
|
23
|
+
class JelliesController < ApplicationController
|
24
|
+
crudify :jelly
|
25
|
+
|
26
|
+
def create
|
27
|
+
@jelly = Jelly.new(params[:jelly])
|
28
|
+
# ... the rest of your custom action
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
Ok that seems easy enough, but what if my action is just a tiny bit different? That's where the _hook methods_ come in...
|
34
|
+
|
35
|
+
### Hook Methods
|
36
|
+
|
37
|
+
Laced into crudify's actions are a module full of methods designed to make customizing your controller quick and simple. Let's examine these methods in further detail starting with create.
|
38
|
+
|
39
|
+
Here's what lines #45-59 in `lib/crudify/class_methods.rb` will produce in our Jellies controller:
|
40
|
+
|
41
|
+
def create
|
42
|
+
# if the position field exists, set this object as last object, given the conditions of this class.
|
43
|
+
if Jelly.column_names.include?("position")
|
44
|
+
params[:jelly].merge!({
|
45
|
+
:position => ((Jelly.maximum(:position, :conditions => "")||-1) + 1)
|
46
|
+
})
|
47
|
+
end
|
48
|
+
@instance = @jelly = Jelly.create(params[:jelly])
|
49
|
+
before_create
|
50
|
+
if @instance.valid? && @instance.save
|
51
|
+
successful_create
|
52
|
+
else
|
53
|
+
failed_create
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
Just before the calls to `valid?` and `save`, you'll see `before_create`; the first hook method in the action. Looking further into the source, `before_create` is nothing more than a blank action, waiting to be overwritten:
|
59
|
+
|
60
|
+
def before_create
|
61
|
+
# just a hook!
|
62
|
+
puts "> Crud::before_create" if @crud_options[:log]
|
63
|
+
before_action
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
Notice that `before_create` calls a second hook; `before_action`. This is a generic hook that fires before every crud method's call to `save`, `update` or `destroy`. This means it might be helpful for you to call `super` when over-riding this method so that the chain of hooks keeps firing. Inside the `before_action` method we'll decide what to use as flash messages with `set_what`. Here's the code for `before_action`:
|
68
|
+
|
69
|
+
def before_action
|
70
|
+
# just a hook!
|
71
|
+
puts "> Crud::before_action" if @crud_options[:log]
|
72
|
+
set_what
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
*Ok Ok, so we're gettin' kind of deep here.* Let's get back to the basic concept; Skinny, sexy and easy on the eyes. (Are we still talking ruby here?)
|
78
|
+
|
79
|
+
class InquiriesController < ApplicationController
|
80
|
+
crudify :inquiry
|
81
|
+
|
82
|
+
def before_create
|
83
|
+
@inquiry.ip_address = request.remote_addr
|
84
|
+
super
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
Or an after-action hook:
|
91
|
+
|
92
|
+
class InquiriesController < ApplicationController
|
93
|
+
crudify :inquiry
|
94
|
+
|
95
|
+
def successful_create
|
96
|
+
InquiryMailer.message(@inquiry).deliver!
|
97
|
+
super
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
### To find out more about crudify, read the source! Here's some helpful links:
|
104
|
+
|
105
|
+
* For available options: [Crudify::Base](https://github.com/citrus/crudify/blob/master/lib/crudify/base.rb)
|
106
|
+
* For available hooks: [Crudify::HookMethods](https://github.com/citrus/crudify/blob/master/lib/crudify/hook_methods.rb)
|
107
|
+
* To see which hooks go where: [Cruidfy::ClassMethods](https://github.com/citrus/crudify/blob/master/lib/crudify/class_methods.rb)
|
108
|
+
|
109
|
+
Or check out the demo app in `test/dummy`...
|
110
|
+
|
111
|
+
|
112
|
+
Testing
|
113
|
+
-------
|
114
|
+
|
115
|
+
Shoulda and Capybara/Selenium tests can be run by cloning the repo and running `rake`:
|
116
|
+
|
117
|
+
git clone git://github.com/citrus/crudify.git
|
118
|
+
cd crudify
|
119
|
+
bundle install
|
120
|
+
rake
|
121
|
+
|
122
|
+
|
123
|
+
To Do
|
124
|
+
-----
|
11
125
|
|
126
|
+
* Documentation & Examples
|
127
|
+
* Nested set tests and demo (haven't even tried this yet :/)
|
128
|
+
* Generally more thorough tests
|
129
|
+
* Refactoring/Optimizing
|
12
130
|
|
13
131
|
|
14
132
|
License
|
data/Rakefile
CHANGED
@@ -3,11 +3,10 @@ require 'rake/testtask'
|
|
3
3
|
Bundler::GemHelper.install_tasks
|
4
4
|
|
5
5
|
Rake::TestTask.new do |t|
|
6
|
-
t.libs << "lib"
|
6
|
+
t.libs << "lib" << "test"
|
7
|
+
t.pattern = 'test/**/*_test.rb'
|
7
8
|
t.verbose = true
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
11
|
desc "Default Task"
|
12
|
-
task :default => [ :test ]
|
13
|
-
|
12
|
+
task :default => [ :test ]
|
data/crudify.gemspec
CHANGED
@@ -11,16 +11,19 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://github.com/citrus/crudify"
|
12
12
|
|
13
13
|
s.summary = %q{Crudify is a dynamic resource controller for Rails 3.}
|
14
|
-
s.description = %q{Crudify is a dynamic resource controller for Rails 3. The
|
14
|
+
s.description = %q{Crudify is a dynamic resource controller for Rails 3. The idea is skinny controllers with powerful hooks for easy customization.}
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
20
|
s.add_dependency('rails', '>= 3.0.0')
|
21
|
-
|
21
|
+
s.add_dependency('will_paginate', '>= 2.3.15')
|
22
22
|
s.add_dependency('meta_search', '>= 1.0.1')
|
23
23
|
|
24
24
|
s.add_development_dependency('shoulda', '>= 2.11.3')
|
25
25
|
s.add_development_dependency('sqlite3-ruby', '>= 1.3.3')
|
26
|
+
s.add_development_dependency('capybara', '>= 0.4.1')
|
27
|
+
s.add_development_dependency('selenium-webdriver', '>= 0.1.3')
|
28
|
+
|
26
29
|
end
|
data/lib/crudify.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_record'
|
3
3
|
require 'action_controller'
|
4
|
+
require 'will_paginate'
|
5
|
+
require 'meta_search'
|
4
6
|
|
5
7
|
require 'crudify/hook_methods'
|
6
8
|
require 'crudify/class_methods'
|
7
9
|
require 'crudify/base'
|
8
10
|
|
9
|
-
module Crudify
|
11
|
+
module Crudify
|
12
|
+
class Engine < Rails::Engine
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
ActionController::Base.send(:include, Crudify::Base)
|
data/lib/crudify/base.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
# Don't forget to add:
|
4
4
|
# resources :plural_model_name_here
|
5
5
|
# to your routes.rb file.
|
6
|
-
# Full documentation about CRUD and resources
|
7
|
-
# -> http://
|
6
|
+
# Full documentation about CRUD and resources start here:
|
7
|
+
# -> http://www.google.com/search?q=rails%20REST
|
8
8
|
# Example (add to your controller):
|
9
|
-
# crudify :foo, {:title_attribute => 'name'}
|
9
|
+
# crudify :foo, { :title_attribute => 'name' }
|
10
10
|
|
11
11
|
|
12
12
|
module Crudify
|
@@ -21,14 +21,15 @@ module Crudify
|
|
21
21
|
{
|
22
22
|
:title_attribute => "title",
|
23
23
|
:use_class_name_as_title => false,
|
24
|
-
:
|
25
|
-
:conditions => '',
|
24
|
+
:paginate => true,
|
26
25
|
:sortable => true,
|
27
26
|
:searchable => true,
|
28
27
|
:include => [],
|
29
|
-
:
|
28
|
+
:order => ('position ASC' if this_class.table_exists? && this_class.column_names.include?('position')),
|
29
|
+
:conditions => '',
|
30
30
|
:search_conditions => '',
|
31
|
-
:redirect_to_url => "admin_#{plural_name}_url"
|
31
|
+
:redirect_to_url => "admin_#{plural_name}_url",
|
32
|
+
:log => Rails.env == 'development'
|
32
33
|
}
|
33
34
|
end
|
34
35
|
|
@@ -1,3 +1,10 @@
|
|
1
|
+
#
|
2
|
+
# Disclaimer:
|
3
|
+
#
|
4
|
+
# The majority of this was originally written by
|
5
|
+
# the splendid fellows at Resolve Digital for their
|
6
|
+
# awesome refinerycms project.
|
7
|
+
#
|
1
8
|
module Crudify
|
2
9
|
|
3
10
|
module ClassMethods
|
@@ -9,7 +16,7 @@ module Crudify
|
|
9
16
|
class_name = singular_name.camelize
|
10
17
|
plural_name = singular_name.pluralize
|
11
18
|
|
12
|
-
options[:
|
19
|
+
options[:paginate] = (options[:paginate] && eval(class_name).respond_to?(:paginate))
|
13
20
|
|
14
21
|
module_eval %(
|
15
22
|
|
@@ -23,8 +30,20 @@ module Crudify
|
|
23
30
|
def set_crud_options
|
24
31
|
@crud_options = #{options}
|
25
32
|
end
|
26
|
-
|
27
|
-
|
33
|
+
|
34
|
+
def set_what
|
35
|
+
return @what if @what
|
36
|
+
what = @crud_options[:use_class_name_as_title] ? @instance.class.to_s.underscore.humanize : @instance.send(@crud_options[:title_attribute].to_sym).inspect
|
37
|
+
what = @instance.class.to_s.underscore.humanize if what.nil? || what == '""'
|
38
|
+
@what = what
|
39
|
+
end
|
40
|
+
|
41
|
+
def index
|
42
|
+
end
|
43
|
+
|
44
|
+
def show
|
45
|
+
end
|
46
|
+
|
28
47
|
def new
|
29
48
|
@#{singular_name} = #{class_name}.new
|
30
49
|
end
|
@@ -62,7 +81,6 @@ module Crudify
|
|
62
81
|
def destroy
|
63
82
|
before_destroy
|
64
83
|
# object gets found by find_#{singular_name} function
|
65
|
-
title = @#{singular_name}.#{options[:title_attribute]}
|
66
84
|
if @#{singular_name}.destroy
|
67
85
|
successful_destroy
|
68
86
|
else
|
@@ -110,14 +128,14 @@ module Crudify
|
|
110
128
|
# If we have already found a set then we don't need to again
|
111
129
|
find_all_#{plural_name} if @#{plural_name}.nil?
|
112
130
|
|
113
|
-
|
131
|
+
paginate_options = {:page => params[:page]}
|
114
132
|
|
115
133
|
# Seems will_paginate doesn't always use the implicit method.
|
116
134
|
if #{class_name}.methods.map(&:to_sym).include?(:per_page)
|
117
|
-
|
135
|
+
paginate_options.update({:per_page => #{class_name}.per_page})
|
118
136
|
end
|
119
137
|
|
120
|
-
set_collection(@#{plural_name}.paginate(
|
138
|
+
set_collection(@#{plural_name}.paginate(paginate_options), false)
|
121
139
|
end
|
122
140
|
|
123
141
|
# Returns results based on the query specified by the user.
|
@@ -137,7 +155,14 @@ module Crudify
|
|
137
155
|
|
138
156
|
# Methods that are only included when this controller is searchable.
|
139
157
|
if options[:searchable]
|
140
|
-
|
158
|
+
|
159
|
+
module_eval %(
|
160
|
+
def searching?
|
161
|
+
params && !params[:search].nil?
|
162
|
+
end
|
163
|
+
)
|
164
|
+
|
165
|
+
if options[:paginate]
|
141
166
|
module_eval %(
|
142
167
|
def index
|
143
168
|
search_all_#{plural_name} if searching?
|
@@ -156,7 +181,7 @@ module Crudify
|
|
156
181
|
)
|
157
182
|
end
|
158
183
|
else
|
159
|
-
if options[:
|
184
|
+
if options[:paginate]
|
160
185
|
module_eval %(
|
161
186
|
def index
|
162
187
|
paginate_all_#{plural_name}
|
@@ -223,18 +248,7 @@ module Crudify
|
|
223
248
|
|
224
249
|
)
|
225
250
|
end
|
226
|
-
|
227
|
-
module_eval %(
|
228
|
-
def self.sortable?
|
229
|
-
#{options[:sortable].to_s}
|
230
|
-
end
|
231
|
-
|
232
|
-
def self.searchable?
|
233
|
-
#{options[:searchable].to_s}
|
234
|
-
end
|
235
|
-
)
|
236
|
-
|
237
|
-
|
251
|
+
|
238
252
|
end
|
239
253
|
|
240
254
|
end
|