shakes 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -4
- data/generators/shakes/shakes_generator.rb +2 -0
- data/generators/shakes/templates/initializer.rb +20 -0
- data/generators/shakes_layout/shakes_layout_generator.rb +0 -2
- data/generators/shakes_views/shakes_views_generator.rb +0 -1
- data/lib/shakes.rb +3 -2
- data/lib/shakes/actions.rb +11 -0
- data/lib/shakes/actions/create.rb +21 -0
- data/lib/shakes/actions/destroy.rb +16 -0
- data/lib/shakes/actions/edit.rb +9 -0
- data/lib/shakes/actions/index.rb +15 -0
- data/lib/shakes/actions/new.rb +15 -0
- data/lib/shakes/actions/show.rb +15 -0
- data/lib/shakes/actions/update.rb +21 -0
- data/lib/shakes/has_the_shakes.rb +84 -0
- metadata +14 -5
- data/lib/shakes/by_convention.rb +0 -162
data/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
__WARNING__ At this point I am making no attempt at maintaining backwards compatibility. Consider Shakes alpha
|
|
2
|
+
level code and use at your own risk.
|
|
3
|
+
|
|
1
4
|
Welcome to Shakes
|
|
2
5
|
=================
|
|
3
6
|
Using `script/generate scaffold` creates a bunch of boilerplate code that you then have to modify by hand every time you
|
|
@@ -24,21 +27,21 @@ Using Shakes is simple. If we were working with a new `Article` resource, we cou
|
|
|
24
27
|
controller and instantly have default actions and views for our new resource:
|
|
25
28
|
|
|
26
29
|
class ArticlesController < ApplicationController
|
|
27
|
-
|
|
30
|
+
has_the_shakes
|
|
28
31
|
end
|
|
29
32
|
|
|
30
|
-
You can limit the actions that are implemented by default passing the `only` or `except` option to `
|
|
33
|
+
You can limit the actions that are implemented by default passing the `only` or `except` option to `has_the_shakes`. For
|
|
31
34
|
example, if you just wanted to have default implementations for `index` and `show` you would use the following code:
|
|
32
35
|
|
|
33
36
|
class ArticlesController < ApplicationController
|
|
34
|
-
|
|
37
|
+
has_the_shakes :only => [:index, :show]
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
Overriding the default implementation for a specific controller is simple. You can just add your custom action
|
|
38
41
|
implementation to your controller as usual:
|
|
39
42
|
|
|
40
43
|
class ArticlesController < ApplicationController
|
|
41
|
-
|
|
44
|
+
has_the_shakes
|
|
42
45
|
|
|
43
46
|
def create
|
|
44
47
|
# my custom create implementation
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Set the default index action module. Default is Shakes::Actions::Index
|
|
2
|
+
# Shakes::HasTheShakes::Configuration.index_action = Shakes::Actions::Index
|
|
3
|
+
|
|
4
|
+
# Set the default new action module. Default is Shakes::Actions::New
|
|
5
|
+
# Shakes::HasTheShakes::Configuration.new_action = Shakes::Actions::New
|
|
6
|
+
|
|
7
|
+
# Set the default create action module. Default is Shakes::Actions::Create
|
|
8
|
+
# Shakes::HasTheShakes::Configuration.create_action = Shakes::Actions::Create
|
|
9
|
+
|
|
10
|
+
# Set the default show action module. Default is Shakes::Actions::Show
|
|
11
|
+
# Shakes::HasTheShakes::Configuration.show_action = Shakes::Actions::Show
|
|
12
|
+
|
|
13
|
+
# Set the default edit action module. Default is Shakes::Actions::Edit
|
|
14
|
+
# Shakes::HasTheShakes::Configuration.edit_action = Shakes::Actions::Edit
|
|
15
|
+
|
|
16
|
+
# Set the default update action module. Default is Shakes::Actions::Update
|
|
17
|
+
# Shakes::HasTheShakes::Configuration.udpate_action = Shakes::Actions::Update
|
|
18
|
+
|
|
19
|
+
# Set the default destroy action module. Default is Shakes::Actions::Destroy
|
|
20
|
+
# Shakes::HasTheShakes::Configuration.destroy_action = Shakes::Actions::Destroy
|
|
@@ -8,10 +8,8 @@ class ShakesLayoutGenerator < Rails::Generator::Base
|
|
|
8
8
|
record do |m|
|
|
9
9
|
m.directory 'app/views/layouts'
|
|
10
10
|
m.directory 'public/stylesheets'
|
|
11
|
-
|
|
12
11
|
m.template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
|
|
13
12
|
m.file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
|
|
14
|
-
|
|
15
13
|
m.dependency 'formtastic', []
|
|
16
14
|
end
|
|
17
15
|
end
|
|
@@ -6,7 +6,6 @@ class ShakesViewsGenerator < Rails::Generator::Base
|
|
|
6
6
|
def manifest
|
|
7
7
|
record do |m|
|
|
8
8
|
m.directory 'app/views/shakes'
|
|
9
|
-
|
|
10
9
|
m.file '../../../app/views/shakes/_form.html.erb', "app/views/shakes/_form.html.erb"
|
|
11
10
|
m.file '../../../app/views/shakes/edit.html.erb', "app/views/shakes/edit.html.erb"
|
|
12
11
|
m.file '../../../app/views/shakes/index.html.erb', "app/views/shakes/index.html.erb"
|
data/lib/shakes.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
module Shakes
|
|
2
|
-
autoload :
|
|
2
|
+
autoload :Actions, 'shakes/actions'
|
|
3
|
+
autoload :HasTheShakes, 'shakes/has_the_shakes'
|
|
3
4
|
end
|
|
4
|
-
ActionController::Base.send :include, Shakes::
|
|
5
|
+
ActionController::Base.send :include, Shakes::HasTheShakes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
autoload :Index, 'shakes/actions/index'
|
|
4
|
+
autoload :New, 'shakes/actions/new'
|
|
5
|
+
autoload :Create, 'shakes/actions/create'
|
|
6
|
+
autoload :Show, 'shakes/actions/show'
|
|
7
|
+
autoload :Edit, 'shakes/actions/edit'
|
|
8
|
+
autoload :Update, 'shakes/actions/update'
|
|
9
|
+
autoload :Destroy, 'shakes/actions/destroy'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
module Create
|
|
4
|
+
def create
|
|
5
|
+
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.new(params[resource_instance_name.to_sym]))
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
if @resource.save
|
|
9
|
+
format.html { redirect_to(@resource, :notice => "#{resource_class.to_s} was successfully created.") }
|
|
10
|
+
format.xml { render :xml => @resource, :status => :created, :location => @resource }
|
|
11
|
+
format.json { render :json => @resource, :status => :created, :location => @resource }
|
|
12
|
+
else
|
|
13
|
+
format.html { render :action => "new" }
|
|
14
|
+
format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
|
|
15
|
+
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
module Destroy
|
|
4
|
+
def destroy
|
|
5
|
+
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
6
|
+
@resource.destroy
|
|
7
|
+
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html { redirect_to(method("#{resource_collection_name}_url".to_sym).call) }
|
|
10
|
+
format.xml { head :ok }
|
|
11
|
+
format.json { head :ok }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
module Index
|
|
4
|
+
def index
|
|
5
|
+
@resources = instance_variable_set("@#{resource_collection_name}", resource_class.all)
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # index.html.erb
|
|
9
|
+
format.xml { render :xml => @resources }
|
|
10
|
+
format.json { render :json => @resources }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
module New
|
|
4
|
+
def new
|
|
5
|
+
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.new)
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # new.html.erb
|
|
9
|
+
format.xml { render :xml => @resource }
|
|
10
|
+
format.json { render :json => @resource }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
module Show
|
|
4
|
+
def show
|
|
5
|
+
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
format.html # show.html.erb
|
|
9
|
+
format.xml { render :xml => @resource }
|
|
10
|
+
format.json { render :json => @resource }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Actions
|
|
3
|
+
module Update
|
|
4
|
+
def update
|
|
5
|
+
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
6
|
+
|
|
7
|
+
respond_to do |format|
|
|
8
|
+
if @resource.update_attributes(params[resource_instance_name.to_sym])
|
|
9
|
+
format.html { redirect_to(@resource, :notice => "#{resource_class.to_s} was successfully updated.") }
|
|
10
|
+
format.xml { head :ok }
|
|
11
|
+
format.json { head :ok }
|
|
12
|
+
else
|
|
13
|
+
format.html { render :action => "edit" }
|
|
14
|
+
format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
|
|
15
|
+
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module HasTheShakes
|
|
3
|
+
class Configuration
|
|
4
|
+
cattr_accessor :index_action, :new_action, :create_action, :show_action, :edit_action, :update_action, :destroy_action
|
|
5
|
+
self.index_action = Shakes::Actions::Index
|
|
6
|
+
self.new_action = Shakes::Actions::New
|
|
7
|
+
self.create_action = Shakes::Actions::Create
|
|
8
|
+
self.show_action = Shakes::Actions::Show
|
|
9
|
+
self.edit_action = Shakes::Actions::Edit
|
|
10
|
+
self.update_action = Shakes::Actions::Update
|
|
11
|
+
self.destroy_action = Shakes::Actions::Destroy
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
SHAKES_ACTIONS = [:index, :new, :create, :show, :edit, :update, :destroy]
|
|
15
|
+
|
|
16
|
+
def self.included(base)
|
|
17
|
+
base.send :extend, ClassMethods
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ClassMethods
|
|
21
|
+
def has_the_shakes(options={})
|
|
22
|
+
cattr_accessor :shakes_resource
|
|
23
|
+
self.shakes_resource = options[:resource] ? options[:resource].to_s : self.name.sub!(/Controller$/,'')
|
|
24
|
+
send :include, InstanceMethods
|
|
25
|
+
|
|
26
|
+
cattr_accessor :shakes_actions
|
|
27
|
+
self.shakes_actions = (options[:only] || SHAKES_ACTIONS) - (options[:except] || [])
|
|
28
|
+
send :include, Configuration.index_action if self.shakes_actions.include? :index
|
|
29
|
+
send :include, Configuration.new_action if self.shakes_actions.include? :new
|
|
30
|
+
send :include, Configuration.create_action if self.shakes_actions.include? :create
|
|
31
|
+
send :include, Configuration.show_action if self.shakes_actions.include? :show
|
|
32
|
+
send :include, Configuration.edit_action if self.shakes_actions.include? :edit
|
|
33
|
+
send :include, Configuration.update_action if self.shakes_actions.include? :update
|
|
34
|
+
send :include, Configuration.destroy_action if self.shakes_actions.include? :destroy
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module InstanceMethods
|
|
39
|
+
def controller_class
|
|
40
|
+
@controller_class ||= Object::const_get(self.class.name.classify)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def resource_class
|
|
44
|
+
@resource_class ||= Object::const_get(self.class.shakes_resource.classify)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def resource_collection_name
|
|
48
|
+
@resource_collection_name ||= self.class.shakes_resource.tableize.pluralize
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def resource_instance_name
|
|
52
|
+
@resource_instance_name ||= self.class.shakes_resource.tableize.singularize
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def render(options = nil, extra_options = {}, &block)
|
|
56
|
+
begin
|
|
57
|
+
super
|
|
58
|
+
rescue ActionView::MissingTemplate
|
|
59
|
+
raise unless locate_resource?
|
|
60
|
+
|
|
61
|
+
options ||= {}
|
|
62
|
+
options[:action] ||= params[:action]
|
|
63
|
+
|
|
64
|
+
raise unless self.shakes_actions.include? options[:action].to_sym
|
|
65
|
+
|
|
66
|
+
controller_class
|
|
67
|
+
resource_class
|
|
68
|
+
resource_collection_name
|
|
69
|
+
resource_instance_name
|
|
70
|
+
|
|
71
|
+
super "shakes/#{options[:action]}.html.erb"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def locate_resource?
|
|
78
|
+
@resources ||= instance_variable_get("@#{resource_collection_name}")
|
|
79
|
+
@resource ||= instance_variable_get("@#{resource_instance_name}")
|
|
80
|
+
(@resources || @resource)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shakes
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 19
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 3
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.3.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Jason Stahl
|
|
@@ -49,12 +49,21 @@ files:
|
|
|
49
49
|
- app/views/shakes/new.html.erb
|
|
50
50
|
- app/views/shakes/show.html.erb
|
|
51
51
|
- generators/shakes/shakes_generator.rb
|
|
52
|
+
- generators/shakes/templates/initializer.rb
|
|
52
53
|
- generators/shakes_layout/shakes_layout_generator.rb
|
|
53
54
|
- generators/shakes_layout/templates/layout.html.erb
|
|
54
55
|
- generators/shakes_layout/templates/stylesheet.css
|
|
55
56
|
- generators/shakes_views/shakes_views_generator.rb
|
|
56
57
|
- generators/shakes_views/templates/touchfile
|
|
57
|
-
- lib/shakes/
|
|
58
|
+
- lib/shakes/actions/create.rb
|
|
59
|
+
- lib/shakes/actions/destroy.rb
|
|
60
|
+
- lib/shakes/actions/edit.rb
|
|
61
|
+
- lib/shakes/actions/index.rb
|
|
62
|
+
- lib/shakes/actions/new.rb
|
|
63
|
+
- lib/shakes/actions/show.rb
|
|
64
|
+
- lib/shakes/actions/update.rb
|
|
65
|
+
- lib/shakes/actions.rb
|
|
66
|
+
- lib/shakes/has_the_shakes.rb
|
|
58
67
|
- lib/shakes.rb
|
|
59
68
|
- rails/init.rb
|
|
60
69
|
- README.md
|
|
@@ -63,7 +72,7 @@ has_rdoc: true
|
|
|
63
72
|
homepage: http://github.com/jfs/shakes
|
|
64
73
|
licenses: []
|
|
65
74
|
|
|
66
|
-
post_install_message: "\n ========================================================================\n Thanks for installing Shakes!\n ------------------------------------------------------------------------\n You can start using Shakes immedialy by adding Shakes to your\n environment.rb configuration as a gem dependency:\n \n config.gem 'shakes'\n\n Then tell Shakes which controllers to provide default implementations\n for by adding `
|
|
75
|
+
post_install_message: "\n ========================================================================\n Thanks for installing Shakes!\n ------------------------------------------------------------------------\n You can start using Shakes immedialy by adding Shakes to your\n environment.rb configuration as a gem dependency:\n \n config.gem 'shakes'\n\n Then tell Shakes which controllers to provide default implementations\n for by adding `has_the_shakes` to them:\n \n class ArticlesController < ApplicationController\n has_the_shakes\n end\n\n Find out more and get involved:\n \n http://github.com/jfs/shakes\n ========================================================================\n "
|
|
67
76
|
rdoc_options: []
|
|
68
77
|
|
|
69
78
|
require_paths:
|
data/lib/shakes/by_convention.rb
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
module Shakes
|
|
2
|
-
module ByConvention
|
|
3
|
-
def self.included(base)
|
|
4
|
-
base.send :extend, ClassMethods
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
CONVENTIONAL_ACTIONS = [:index, :new, :create, :show, :edit, :update, :destroy]
|
|
8
|
-
|
|
9
|
-
module ClassMethods
|
|
10
|
-
def by_convention(options={})
|
|
11
|
-
cattr_accessor :resource_type
|
|
12
|
-
self.resource_type = options[:resource] ? options[:resource].to_s : self.name.sub!(/Controller$/,'')
|
|
13
|
-
send :include, InstanceMethods
|
|
14
|
-
|
|
15
|
-
cattr_accessor :conventional_actions
|
|
16
|
-
self.conventional_actions = (options[:only] || CONVENTIONAL_ACTIONS) - (options[:except] || [])
|
|
17
|
-
send :include, IndexInstanceMethods if self.conventional_actions.include? :index
|
|
18
|
-
send :include, NewInstanceMethods if self.conventional_actions.include? :new
|
|
19
|
-
send :include, CreateInstanceMethods if self.conventional_actions.include? :create
|
|
20
|
-
send :include, ShowInstanceMethods if self.conventional_actions.include? :show
|
|
21
|
-
send :include, EditInstanceMethods if self.conventional_actions.include? :edit
|
|
22
|
-
send :include, UpdateInstanceMethods if self.conventional_actions.include? :update
|
|
23
|
-
send :include, DestroyInstanceMethods if self.conventional_actions.include? :destroy
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
module InstanceMethods
|
|
28
|
-
def controller_class
|
|
29
|
-
@controller_class ||= Object::const_get(self.class.name.classify)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def resource_class
|
|
33
|
-
@resource_class ||= Object::const_get(self.class.resource_type.classify)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def resource_collection_name
|
|
37
|
-
@resource_collection_name ||= self.class.resource_type.tableize.pluralize
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def resource_instance_name
|
|
41
|
-
@resource_instance_name ||= self.class.resource_type.tableize.singularize
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def render(options = nil, extra_options = {}, &block)
|
|
45
|
-
begin
|
|
46
|
-
super
|
|
47
|
-
rescue ActionView::MissingTemplate
|
|
48
|
-
raise unless locate_resource?
|
|
49
|
-
|
|
50
|
-
options ||= {}
|
|
51
|
-
options[:action] ||= params[:action]
|
|
52
|
-
|
|
53
|
-
controller_class
|
|
54
|
-
resource_class
|
|
55
|
-
resource_collection_name
|
|
56
|
-
resource_instance_name
|
|
57
|
-
|
|
58
|
-
super "shakes/#{options[:action]}.html.erb"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
private
|
|
63
|
-
|
|
64
|
-
def locate_resource?
|
|
65
|
-
@resources ||= instance_variable_get("@#{resource_collection_name}")
|
|
66
|
-
@resource ||= instance_variable_get("@#{resource_instance_name}")
|
|
67
|
-
(@resources || @resource)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
module IndexInstanceMethods
|
|
72
|
-
def index
|
|
73
|
-
@resources = instance_variable_set("@#{resource_collection_name}", resource_class.all)
|
|
74
|
-
|
|
75
|
-
respond_to do |format|
|
|
76
|
-
format.html # index.html.erb
|
|
77
|
-
format.xml { render :xml => @resources }
|
|
78
|
-
format.json { render :json => @resources }
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
module NewInstanceMethods
|
|
84
|
-
def new
|
|
85
|
-
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.new)
|
|
86
|
-
|
|
87
|
-
respond_to do |format|
|
|
88
|
-
format.html # new.html.erb
|
|
89
|
-
format.xml { render :xml => @resource }
|
|
90
|
-
format.json { render :json => @resource }
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
module CreateInstanceMethods
|
|
96
|
-
def create
|
|
97
|
-
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.new(params[resource_instance_name.to_sym]))
|
|
98
|
-
|
|
99
|
-
respond_to do |format|
|
|
100
|
-
if @resource.save
|
|
101
|
-
format.html { redirect_to(@resource, :notice => "#{resource_class.to_s} was successfully created.") }
|
|
102
|
-
format.xml { render :xml => @resource, :status => :created, :location => @resource }
|
|
103
|
-
format.json { render :json => @resource, :status => :created, :location => @resource }
|
|
104
|
-
else
|
|
105
|
-
format.html { render :action => "new" }
|
|
106
|
-
format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
|
|
107
|
-
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
module ShowInstanceMethods
|
|
114
|
-
def show
|
|
115
|
-
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
116
|
-
|
|
117
|
-
respond_to do |format|
|
|
118
|
-
format.html # show.html.erb
|
|
119
|
-
format.xml { render :xml => @resource }
|
|
120
|
-
format.json { render :json => @resource }
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
module EditInstanceMethods
|
|
126
|
-
def edit
|
|
127
|
-
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
module UpdateInstanceMethods
|
|
132
|
-
def update
|
|
133
|
-
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
134
|
-
|
|
135
|
-
respond_to do |format|
|
|
136
|
-
if @resource.update_attributes(params[resource_instance_name.to_sym])
|
|
137
|
-
format.html { redirect_to(@resource, :notice => "#{resource_class.to_s} was successfully updated.") }
|
|
138
|
-
format.xml { head :ok }
|
|
139
|
-
format.json { head :ok }
|
|
140
|
-
else
|
|
141
|
-
format.html { render :action => "edit" }
|
|
142
|
-
format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
|
|
143
|
-
format.json { render :json => @resource.errors, :status => :unprocessable_entity }
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
module DestroyInstanceMethods
|
|
150
|
-
def destroy
|
|
151
|
-
@resource = instance_variable_set("@#{resource_instance_name}", resource_class.find(params[:id]))
|
|
152
|
-
@resource.destroy
|
|
153
|
-
|
|
154
|
-
respond_to do |format|
|
|
155
|
-
format.html { redirect_to(method("#{resource_collection_name}_url".to_sym).call) }
|
|
156
|
-
format.xml { head :ok }
|
|
157
|
-
format.json { head :ok }
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|