Permalink
Browse files

Update inherited resources

  • Loading branch information...
1 parent 3d9c8fb commit 58625a12f15dd9a328681e528e8c3f7d493be994 @joshuaclayton committed Dec 21, 2009
Showing with 507 additions and 139 deletions.
  1. +2 −3 config/environment.rb
  2. +28 −26 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/.specification
  3. +10 −0 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/CHANGELOG
  4. 0 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/MIT-LICENSE
  5. +33 −14 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/README.rdoc
  6. +4 −0 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/Rakefile
  7. 0 ...gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources.rb
  8. +15 −10 ...sevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/actions.rb
  9. +2 −1 ...{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/base.rb
  10. +67 −6 ...im-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/base_helpers.rb
  11. 0 ...erited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/belongs_to_helpers.rb
  12. +17 −11 ...m-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/class_methods.rb
  13. +2 −2 .../{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/dsl.rb
  14. +1 −1 ...-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/dumb_responder.rb
  15. +18 −0 ...herited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/has_scope_helpers.rb
  16. 0 ...herited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/legacy/respond_to.rb
  17. 0 ...nherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/legacy/responder.rb
  18. 0 ...rited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/polymorphic_helpers.rb
  19. 0 ...herited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/singleton_helpers.rb
  20. +4 −1 ...lim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/lib/inherited_resources/url_helpers.rb
  21. +3 −0 vendor/gems/inherited_resources-0.9.4/lib/inherited_resources/version.rb
  22. +1 −1 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/aliases_test.rb
  23. 0 .../{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/association_chain_test.rb
  24. +20 −7 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/base_test.rb
  25. +3 −3 ...or/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/belongs_to_test.rb
  26. +19 −6 ...gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/class_methods_test.rb
  27. +162 −0 vendor/gems/inherited_resources-0.9.4/test/customized_base_test.rb
  28. +7 −7 ...sevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/customized_belongs_to_test.rb
  29. +3 −3 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/defaults_test.rb
  30. +7 −7 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/flash_test.rb
  31. +29 −2 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/has_scope_test.rb
  32. 0 .../{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/nested_belongs_to_test.rb
  33. +8 −8 ...josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/optional_belongs_to_test.rb
  34. +6 −6 ...r/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/polymorphic_test.rb
  35. 0 ...r/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/redirect_to_test.rb
  36. 0 ...or/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/respond_to_test.rb
  37. +3 −3 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/singleton_test.rb
  38. +9 −1 vendor/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/test_helper.rb
  39. +24 −9 ...r/gems/{josevalim-inherited_resources-0.9.1 → inherited_resources-0.9.4}/test/url_helpers_test.rb
  40. +0 −1 vendor/gems/josevalim-inherited_resources-0.9.1/VERSION
@@ -3,8 +3,7 @@
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
- config.gem "josevalim-inherited_resources",
- :lib => "inherited_resources",
- :source => "http://gems.github.com"
+ config.gem "inherited_resources", :version => ">= 0.9.4"
+
config.time_zone = "UTC"
end
@@ -1,15 +1,15 @@
--- !ruby/object:Gem::Specification
-name: josevalim-inherited_resources
+name: inherited_resources
version: !ruby/object:Gem::Version
- version: 0.9.1
+ version: 0.9.4
platform: ruby
authors:
- "Jos\xC3\xA9 Valim"
autorequire:
bindir: bin
cert_chain: []
-date: 2009-09-01 00:00:00 -04:00
+date: 2009-12-11 00:00:00 -05:00
default_executable:
dependencies: []
@@ -26,7 +26,6 @@ files:
- MIT-LICENSE
- README.rdoc
- Rakefile
-- VERSION
- lib/inherited_resources.rb
- lib/inherited_resources/actions.rb
- lib/inherited_resources/base.rb
@@ -41,23 +40,25 @@ files:
- lib/inherited_resources/polymorphic_helpers.rb
- lib/inherited_resources/singleton_helpers.rb
- lib/inherited_resources/url_helpers.rb
-- test/respond_to_test.rb
-- test/customized_belongs_to_test.rb
-- test/nested_belongs_to_test.rb
+- lib/inherited_resources/version.rb
+- test/aliases_test.rb
+- test/association_chain_test.rb
- test/base_test.rb
-- test/redirect_to_test.rb
-- test/has_scope_test.rb
+- test/belongs_to_test.rb
- test/class_methods_test.rb
-- test/association_chain_test.rb
-- test/aliases_test.rb
+- test/customized_base_test.rb
+- test/customized_belongs_to_test.rb
+- test/defaults_test.rb
- test/flash_test.rb
-- test/url_helpers_test.rb
-- test/belongs_to_test.rb
+- test/has_scope_test.rb
+- test/nested_belongs_to_test.rb
+- test/optional_belongs_to_test.rb
- test/polymorphic_test.rb
-- test/defaults_test.rb
+- test/redirect_to_test.rb
+- test/respond_to_test.rb
- test/singleton_test.rb
-- test/optional_belongs_to_test.rb
- test/test_helper.rb
+- test/url_helpers_test.rb
has_rdoc: true
homepage: http://github.com/josevalim/inherited_resources
licenses: []
@@ -87,20 +88,21 @@ signing_key:
specification_version: 3
summary: Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.
test_files:
-- test/respond_to_test.rb
-- test/customized_belongs_to_test.rb
-- test/nested_belongs_to_test.rb
+- test/aliases_test.rb
+- test/association_chain_test.rb
- test/base_test.rb
-- test/redirect_to_test.rb
-- test/has_scope_test.rb
+- test/belongs_to_test.rb
- test/class_methods_test.rb
-- test/association_chain_test.rb
-- test/aliases_test.rb
+- test/customized_base_test.rb
+- test/customized_belongs_to_test.rb
+- test/defaults_test.rb
- test/flash_test.rb
-- test/url_helpers_test.rb
-- test/belongs_to_test.rb
+- test/has_scope_test.rb
+- test/nested_belongs_to_test.rb
+- test/optional_belongs_to_test.rb
- test/polymorphic_test.rb
-- test/defaults_test.rb
+- test/redirect_to_test.rb
+- test/respond_to_test.rb
- test/singleton_test.rb
-- test/optional_belongs_to_test.rb
- test/test_helper.rb
+- test/url_helpers_test.rb
@@ -1,5 +1,15 @@
+# Version 0.9.4
+
+* Since InheritedResouces 0.9.4, :notice and :error in I18n messages are deprecated in
+favor of :success and :failure. If you try to access them, a deprecation message is shown.
+If you want to skip the message, because you are sure you *won't* access such keys,
+just set DO_NOT_SET_NOTICE_MESSAGE to true somewhere in your app.
+
# Version 0.9
+* Allow dual blocks in destroy;
+* Added :if and :unless to has_scope (thanks to Jack Danger);
+* Added create_resource, update_resource and delete_resource hooks (thanks to Carlos Antonio da Silva);
* Backported ActionController::Responder from Rails 3;
* Added parent_url helper;
* Added association_chain helper (as suggested by http://github.com/emmanuel);
@@ -1,6 +1,6 @@
Inherited Resources
License: MIT
-Version: 0.9.1
+Version: 0.9.4
== Description
@@ -9,7 +9,10 @@ all restful actions so you just have to focus on what is important. It makes
your controllers more powerful and cleaner at the same time.
Plus, making your controllers follow a pattern, it helps you to write better
-code by following fat models and skinny controllers convention.
+code by following fat models and skinny controllers convention. There is
+a screencast made by Fabio Akita about its features:
+
+http://akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources
Inherited Resources is tested and compatible with Rails 2.2.x and Rails 2.3.x.
@@ -20,13 +23,26 @@ keywords: resources, controller, singleton, belongs_to, polymorphic, named_scope
Install Inherited Resources is very easy. It is stored in GitHub, so just run
the following:
- gem sources -a http://gems.github.com
- sudo gem install josevalim-inherited_resources
+ gem sources -a http://gemcutter.org
+ sudo gem install inherited_resources
If you want it as plugin, just do:
script/plugin install git://github.com/josevalim/inherited_resources.git
+== Rspec known bug
+
+When used with integrate_views equals to false, rspec overwrites default_render,
+render and some other controller methods which makes Inherited Resources not work
+properly. In such cases, you have to set integrate_views to true.
+
+== Deprecation
+
+Since InheritedResouces 0.9.4, :notice and :error in I18n messages are deprecated in
+favor of :success and :failure. If you try to access them, a deprecation message is shown.
+If you want to skip the message, because you are sure you *won't* access such keys,
+just set DO_NOT_SET_NOTICE_MESSAGE to true somewhere in your app.
+
== Basic Usage
To use Inherited Resources you just have to inherit (duh) it:
@@ -117,7 +133,7 @@ projects collection:
class ProjectsController < InheritedResources::Base
protected
def collection
- @projects ||= end_of_association_chain.paginate(params[:page]).all
+ @projects ||= end_of_association_chain.paginate(:page => params[:page])
end
end
@@ -223,7 +239,7 @@ clean and organized inside the same action.
For those DSL lovers, InheritedResources won't leave you alone. You can overwrite
your success/failure blocks straight from your class binding. For it, you just
-need to add a DSL block to your application controller:
+need to add a DSL module to your application controller:
class ApplicationController < ActionController::Base
include InheritedResources::DSL
@@ -251,8 +267,8 @@ on projects controller, it will search for:
flash.projects.create.status
flash.actions.create.status
-The status can be :notice (when the object can be created, updated
-or destroyed with success) or :error (when the objecy cannot be created
+The status can be :success (when the object can be created, updated
+or destroyed with success) or :failure (when the objecy cannot be created
or updated).
Those messages are interpolated by using the resource class human name, which
@@ -261,7 +277,7 @@ is also localized and it means you can set:
flash:
actions:
create:
- notice: "Hooray! {{resource_name}} was successfully created!"
+ success: "Hooray! {{resource_name}} was successfully created!"
It will replace {{resource_name}} by the human name of the resource class,
which is "Project" in this case.
@@ -272,7 +288,7 @@ the title of the project while updating a project. Well, that's easy also:
flash:
projects:
update:
- notice: "Hooray! The project "{{project_title}}" was updated!"
+ success: "Hooray! The project "{{project_title}}" was updated!"
Since :project_title is not available for interpolation by default, you have
to overwrite interpolation_options.
@@ -419,6 +435,9 @@ When using polymorphic associations, you get some free helpers:
parent_class #=> Task
parent #=> @task
+Right now, Inherited Resources is limited and does not allow you
+to have two polymorphic associations nested.
+
== Optional belongs to
Later you decide to create a view to show all comments, independent if they belong
@@ -505,8 +524,8 @@ associations, that relies on Rails polymorphic_url).
== Bugs and Feedback
-If you discover any bugs, please send an e-mail to jose.valim@plataformatec.com.br
-If you just want to give some positive feedback or drop a line, that's fine too!
+If you discover any bugs or want to drop a line, join us in the mailing list:
+
+http://groups.google.com/group/inherited_resources
-Copyright (c) 2009 José Valim<br />
-http://blog.plataformatec.com.br/
+Copyright (c) 2009 José Valim http://blog.plataformatec.com.br
@@ -3,11 +3,13 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
+require File.join(File.dirname(__FILE__), 'lib', 'inherited_resources', 'version')
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "inherited_resources"
+ s.version = InheritedResources::VERSION
s.rubyforge_project = "inherited_resources"
s.summary = "Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important."
s.email = "jose.valim@gmail.com"
@@ -16,6 +18,8 @@ begin
s.authors = ['José Valim']
s.files = FileList["[A-Z]*", "{lib}/**/*"]
end
+
+ Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
@@ -30,12 +30,12 @@ def edit(&block)
def create(options={}, &block)
object = build_resource
- if object.save
- set_flash_message!(:notice, '{{resource_name}} was successfully created.')
+ if create_resource(object)
+ set_flash_message!(:success, '{{resource_name}} was successfully created.')
options[:location] ||= resource_url rescue nil
respond_with_dual_blocks(object, options, true, block)
else
- set_flash_message!(:error)
+ set_flash_message!(:failure)
respond_with_dual_blocks(object, options, false, block)
end
end
@@ -45,12 +45,12 @@ def create(options={}, &block)
def update(options={}, &block)
object = resource
- if object.update_attributes(params[resource_instance_name])
- set_flash_message!(:notice, '{{resource_name}} was successfully updated.')
+ if update_resource(object, params[resource_instance_name])
+ set_flash_message!(:success, '{{resource_name}} was successfully updated.')
options[:location] ||= resource_url rescue nil
respond_with_dual_blocks(object, options, true, block)
else
- set_flash_message!(:error)
+ set_flash_message!(:failure)
respond_with_dual_blocks(object, options, false, block)
end
end
@@ -59,11 +59,15 @@ def update(options={}, &block)
# DELETE /resources/1
def destroy(options={}, &block)
object = resource
- object.destroy
-
- set_flash_message!(:notice, '{{resource_name}} was successfully destroyed.')
options[:location] ||= collection_url rescue nil
- respond_with_dual_blocks(object, options, nil, block)
+
+ if destroy_resource(object)
+ set_flash_message!(:success, '{{resource_name}} was successfully destroyed.')
+ respond_with_dual_blocks(object, options, true, block)
+ else
+ set_flash_message!(:failure, '{{resource_name}} could not be destroyed.')
+ respond_with_dual_blocks(object, options, false, block)
+ end
end
alias :destroy! :destroy
@@ -72,3 +76,4 @@ def destroy(options={}, &block)
end
end
+
@@ -25,7 +25,8 @@ def self.inherit_resources(base)
helper_method :collection_url, :collection_path, :resource_url, :resource_path,
:new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path,
- :parent_url, :parent_path, :resource, :collection, :resource_class, :association_chain
+ :parent_url, :parent_path, :resource, :collection, :resource_class, :association_chain,
+ :resource_instance_name, :resource_collection_name
base.with_options :instance_writer => false do |c|
c.class_inheritable_accessor :resource_class
Oops, something went wrong.

0 comments on commit 58625a1

Please sign in to comment.