aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-10-17 15:56:44 -0300
committerJosé Valim <jose.valim@gmail.com>2009-10-17 15:56:44 -0300
commit1f9d234a6b567e68d97e71da6f19bd126e7f7058 (patch)
tree601ea9ceba21bb3f90173c38b81578aa5920eb86 /railties/lib
parent03c5a0e5c4c9888c54265d6ef97136854e0ff9e4 (diff)
downloadrails-1f9d234a6b567e68d97e71da6f19bd126e7f7058.tar.gz
rails-1f9d234a6b567e68d97e71da6f19bd126e7f7058.tar.bz2
rails-1f9d234a6b567e68d97e71da6f19bd126e7f7058.zip
By default use ActiveModel API in controller generators, unless otherwise specified [#3123 status:resolved]
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators/active_model.rb18
-rw-r--r--railties/lib/rails/generators/active_record.rb34
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb17
3 files changed, 16 insertions, 53 deletions
diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb
index 1a849a0e02..fe6321af30 100644
--- a/railties/lib/rails/generators/active_model.rb
+++ b/railties/lib/rails/generators/active_model.rb
@@ -32,7 +32,7 @@ module Rails
# GET index
def self.all(klass)
- raise NotImplementedError
+ "#{klass}.all"
end
# GET show
@@ -40,34 +40,38 @@ module Rails
# PUT update
# DELETE destroy
def self.find(klass, params=nil)
- raise NotImplementedError
+ "#{klass}.find(#{params})"
end
# GET new
# POST create
def self.build(klass, params=nil)
- raise NotImplementedError
+ if params
+ "#{klass}.new(#{params})"
+ else
+ "#{klass}.new"
+ end
end
# POST create
def save
- raise NotImplementedError
+ "#{name}.save"
end
# PUT update
def update_attributes(params=nil)
- raise NotImplementedError
+ "#{name}.update_attributes(#{params})"
end
# POST create
# PUT update
def errors
- raise NotImplementedError
+ "#{name}.errors"
end
# DELETE destroy
def destroy
- raise NotImplementedError
+ "#{name}.destroy"
end
end
end
diff --git a/railties/lib/rails/generators/active_record.rb b/railties/lib/rails/generators/active_record.rb
index c03ea59c1b..babad33db3 100644
--- a/railties/lib/rails/generators/active_record.rb
+++ b/railties/lib/rails/generators/active_record.rb
@@ -18,39 +18,5 @@ module ActiveRecord
end
end
end
-
- class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
- def self.all(klass)
- "#{klass}.all"
- end
-
- def self.find(klass, params=nil)
- "#{klass}.find(#{params})"
- end
-
- def self.build(klass, params=nil)
- if params
- "#{klass}.new(#{params})"
- else
- "#{klass}.new"
- end
- end
-
- def save
- "#{name}.save"
- end
-
- def update_attributes(params=nil)
- "#{name}.update_attributes(#{params})"
- end
-
- def errors
- "#{name}.errors"
- end
-
- def destroy
- "#{name}.destroy"
- end
- end
end
end
diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index d4b0d4b945..0385581083 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -1,3 +1,5 @@
+require 'rails/generators/active_model'
+
module Rails
module Generators
# Deal with controller names on scaffold and add some helpers to deal with
@@ -47,20 +49,11 @@ module Rails
raise "You need to have :orm as class option to invoke orm_class and orm_instance"
end
- active_model = "#{options[:orm].to_s.classify}::Generators::ActiveModel"
-
- # If the orm was not loaded, try to load it at "generators/orm",
- # for example "generators/active_record" or "generators/sequel".
begin
- klass = active_model.constantize
- rescue NameError
- require "rails/generators/#{options[:orm]}"
+ "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize
+ rescue NameError => e
+ Rails::Generators::ActiveModel
end
-
- # Try once again after loading the file with success.
- klass ||= active_model.constantize
- rescue Exception => e
- raise Error, "Could not load #{active_model}, skipping controller. Error: #{e.message}."
end
end