josevalim-inherited_resources 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/inherited_resources/actions.rb +1 -1
- data/lib/inherited_resources/base_helpers.rb +4 -4
- data/lib/inherited_resources/respond_to.rb +14 -11
- data/test/test_helper.rb +2 -2
- metadata +2 -2
data/README
CHANGED
@@ -30,7 +30,7 @@ module InheritedResources
|
|
30
30
|
|
31
31
|
# POST /resources
|
32
32
|
def create(redirect_url=nil, &block)
|
33
|
-
object = build_resource
|
33
|
+
object = build_resource
|
34
34
|
respond_block, redirect_block = select_block_by_arity(block)
|
35
35
|
|
36
36
|
if object.save
|
@@ -42,11 +42,11 @@ module InheritedResources
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# This method is responsable for building the object on :new and :create
|
45
|
-
# methods.
|
46
|
-
#
|
45
|
+
# methods. If you overwrite it, don't forget to cache the result in an
|
46
|
+
# instance variable.
|
47
47
|
#
|
48
|
-
def build_resource
|
49
|
-
get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build,
|
48
|
+
def build_resource
|
49
|
+
get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, params[resource_instance_name]))
|
50
50
|
end
|
51
51
|
|
52
52
|
# This class allows you to set a instance variable to begin your
|
@@ -59,9 +59,6 @@ module ActionController
|
|
59
59
|
end
|
60
60
|
class_inheritable_reader :formats_for_respond_to
|
61
61
|
|
62
|
-
# By default, responds only to :html
|
63
|
-
respond_to :html
|
64
|
-
|
65
62
|
# Method to clear all respond_to declared until the current controller.
|
66
63
|
# This is like freeing the controller from the inheritance chain. :)
|
67
64
|
#
|
@@ -71,6 +68,20 @@ module ActionController
|
|
71
68
|
write_inheritable_hash(:formats_for_respond_to, formats)
|
72
69
|
end
|
73
70
|
|
71
|
+
# By default, responds only to :html
|
72
|
+
respond_to :html
|
73
|
+
|
74
|
+
# If ApplicationController is already defined around here, we recriate
|
75
|
+
# the formats_for_respond_to hash. Since we respond only to :html by
|
76
|
+
# default, this is as easy as settings the :formats_for_respond_to key
|
77
|
+
# to {:html=>{}}.
|
78
|
+
#
|
79
|
+
if defined?(ApplicationController)
|
80
|
+
if inheritable = ApplicationController.instance_variable_get("@inheritable_attributes")
|
81
|
+
inheritable.merge!(:formats_for_respond_to => {:html => {}}) if inheritable
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
74
85
|
# respond_with accepts an object and tries to render a view based in the
|
75
86
|
# controller and actions that called respond_with. If the view cannot be
|
76
87
|
# found, it will try to call :to_format in the object.
|
@@ -258,14 +269,6 @@ module ActionController
|
|
258
269
|
responder.action_respond_to_format?(default_template_format) && template_exists?
|
259
270
|
end
|
260
271
|
|
261
|
-
# If ApplicationController is already defined around here, we should call
|
262
|
-
# inherited_with_inheritable_attributes to insert formats_for_respond_to.
|
263
|
-
# This usually happens only on Rails 2.3.
|
264
|
-
#
|
265
|
-
if defined?(ApplicationController)
|
266
|
-
self.send(:inherited_with_inheritable_attributes, ApplicationController)
|
267
|
-
end
|
268
|
-
|
269
272
|
end
|
270
273
|
|
271
274
|
module MimeResponds #:nodoc:
|
data/test/test_helper.rb
CHANGED
@@ -14,12 +14,12 @@ require 'action_controller/test_process'
|
|
14
14
|
I18n.load_path << File.join(File.dirname(__FILE__), 'locales', 'en.yml')
|
15
15
|
I18n.reload!
|
16
16
|
|
17
|
+
class ApplicationController < ActionController::Base; end
|
18
|
+
|
17
19
|
# Add IR to load path and load the main file
|
18
20
|
ActiveSupport::Dependencies.load_paths << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
19
21
|
require_dependency 'inherited_resources'
|
20
22
|
|
21
|
-
class ApplicationController < ActionController::Base; end
|
22
|
-
|
23
23
|
ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
|
24
24
|
|
25
25
|
ActionController::Routing::Routes.draw do |map|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josevalim-inherited_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|