action_crud 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/action_crud/controller.rb +10 -1
- data/lib/action_crud/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31a0e2593bbdae590abea1ce539011e21fdd36c3
|
4
|
+
data.tar.gz: 9fc1280a4be0878bd1397c68ad44073b6f54d3cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2c154c7ebc4d3fbc09d7a5ad7398e0fbbb106eefcd42881baa1fc2cfcefca3a2ed829c2f0a447372680ee2c2c4520addede041906ce2315fcb81f3fa04c6df
|
7
|
+
data.tar.gz: 415a63a957abee12b31c92eb8c671e635c81d7d8d3232fe5c658c65d0700061ea323e9a39ab6f2b4d005dc18f5c57d4fe91c73ea8c2a14a1b735e7882c899fc6
|
data/README.md
CHANGED
@@ -81,6 +81,24 @@ class Post < ActionController::Base
|
|
81
81
|
end
|
82
82
|
```
|
83
83
|
|
84
|
+
Permitted parameters can also be set in your models or records, if you want to apply some logic, by adding a `permitted_attributes` function. The parameters are loaded with priority `controller` then `record` then `model`, like the example below:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class Post < ActiveRecord::Base
|
88
|
+
# Set permitted_attributes in model
|
89
|
+
def self.permitted_attributes
|
90
|
+
[:title, :content, :comments]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Set permitted_attributes in record
|
94
|
+
def permitted_attributes
|
95
|
+
if new_record?
|
96
|
+
[:title, :content]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
84
102
|
If you use a pagination gem like [SmartPagination](https://github.com/hardpixel/smart-pagination), the index records will be automagically paginated. To set the results limit per page (default: 20), use the `set_per_page` function:
|
85
103
|
|
86
104
|
```ruby
|
@@ -21,6 +21,7 @@ module ActionCrud
|
|
21
21
|
|
22
22
|
# Action callbacks
|
23
23
|
before_action :set_record, only: [:show, :edit, :update, :destroy]
|
24
|
+
before_action :set_permitted_params, if: -> { permitted_params.empty? }
|
24
25
|
end
|
25
26
|
|
26
27
|
class_methods do
|
@@ -136,7 +137,7 @@ module ActionCrud
|
|
136
137
|
|
137
138
|
# Get model
|
138
139
|
def model
|
139
|
-
model_class
|
140
|
+
record.nil? ? model_class : record.class
|
140
141
|
end
|
141
142
|
|
142
143
|
alias :current_model :model
|
@@ -176,5 +177,13 @@ module ActionCrud
|
|
176
177
|
def record_params
|
177
178
|
params.require(:"#{instance_name}").permit permitted_params
|
178
179
|
end
|
180
|
+
|
181
|
+
# Set permitted params from record/model if not set in controller.
|
182
|
+
def set_permitted_params
|
183
|
+
att_method = :permitted_attributes
|
184
|
+
attributes = record.try(att_method) || model.try(att_method)
|
185
|
+
|
186
|
+
self.permitted_params = Array(attributes)
|
187
|
+
end
|
179
188
|
end
|
180
189
|
end
|
data/lib/action_crud/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_crud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonian Guveli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|