action_args 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ccd1f7e360a0022028839049722507a17dd7cee
|
4
|
+
data.tar.gz: 47dbf523322610689ceebdab7262f48b5a1c81f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4120e5d6c4e0ad9e6d264859d98211cd9448f52138cf3fcb4918479195ab6f5c785dec3c8ea0335bc1d4573f7f86d926194965adc8da15feaaadf817d3b7036c
|
7
|
+
data.tar.gz: a6d93141be8036c6f3728489f9a305be1ca48a826342fa3d01af43bdbcff5b1d0716d0f123bbadd4a33b2685fbec853f4f390345872db6232dd904741af3523f
|
data/README.md
CHANGED
@@ -86,6 +86,16 @@ class UsersController < ApplicationController
|
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
+
By default, action_args deduces the target model name from the controller name.
|
90
|
+
For example, the `permits` call in `UsersController` expects the model name to be `User`.
|
91
|
+
If this is not the case, you can specify the :model_name option:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class MembersController < ApplicationController
|
95
|
+
# white-lists User model's attributes
|
96
|
+
permits :name, :age, model_name: 'User'
|
97
|
+
end
|
98
|
+
```
|
89
99
|
|
90
100
|
## The Scaffold Generator
|
91
101
|
|
@@ -24,6 +24,8 @@ module AbstractController
|
|
24
24
|
# end
|
25
25
|
#
|
26
26
|
def self.permits(*attributes)
|
27
|
+
options = attributes.extract_options!
|
28
|
+
@permitting_model_name = options[:model_name] if options.has_key? :model_name
|
27
29
|
@permitted_attributes = attributes
|
28
30
|
end
|
29
31
|
# no StrongParameters
|
@@ -25,8 +25,8 @@ module ActionArgs
|
|
25
25
|
# permits declared model attributes in the params Hash
|
26
26
|
# note that this method mutates the given params Hash
|
27
27
|
def self.strengthen_params!(controller_class, method_parameters, params)
|
28
|
-
target_model_name = controller_class.name.sub(/.+::/, '').sub(/Controller$/, '').singularize.underscore.to_sym
|
29
|
-
permitted_attributes = controller_class.instance_variable_get '@permitted_attributes'
|
28
|
+
target_model_name = (controller_class.instance_variable_get(:'@permitting_model_name') || controller_class.name.sub(/.+::/, '').sub(/Controller$/, '')).singularize.underscore.to_sym
|
29
|
+
permitted_attributes = controller_class.instance_variable_get :'@permitted_attributes'
|
30
30
|
|
31
31
|
method_parameters.each do |type, key|
|
32
32
|
if (key == target_model_name) && permitted_attributes
|
data/lib/action_args/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe UserMailer do
|
4
4
|
describe '#send_email_without_args' do
|
5
5
|
it "should not raise NameError: undefined local variable or method `params' for ..." do
|
6
|
-
expect{ UserMailer.send_email_without_args }.to_not raise_error
|
6
|
+
expect{ UserMailer.send_email_without_args }.to_not raise_error
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -157,6 +157,14 @@ describe ActionArgs::ParamsHandler do
|
|
157
157
|
end
|
158
158
|
KWARGS_TEST
|
159
159
|
end
|
160
|
+
|
161
|
+
describe '"model_name" option' do
|
162
|
+
let(:controller) { PiyoController ||= Class.new(ApplicationController) { permits :a, :b, model_name: 'Foo'; def a(foo) end } }
|
163
|
+
subject { params[:foo] }
|
164
|
+
it { should be_permitted }
|
165
|
+
its([:a]) { should be }
|
166
|
+
its([:b]) { should be }
|
167
|
+
end
|
160
168
|
end
|
161
169
|
end
|
162
170
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_args
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails plugin gem that supports Merbish style controller action arguments.
|
14
14
|
email:
|
@@ -76,3 +76,4 @@ test_files:
|
|
76
76
|
- spec/mailers/action_mailer_spec.rb
|
77
77
|
- spec/params_handler/params_handler_spec.rb
|
78
78
|
- spec/spec_helper.rb
|
79
|
+
has_rdoc:
|