dynamic_scaffold 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/app/views/dynamic_scaffold/bootstrap/_form.html.erb +7 -1
- data/lib/dynamic_scaffold/config.rb +10 -0
- data/lib/dynamic_scaffold/controller.rb +1 -2
- data/lib/dynamic_scaffold/controller_utilities.rb +2 -1
- data/lib/dynamic_scaffold/form/item/base.rb +13 -0
- data/lib/dynamic_scaffold/version.rb +1 -1
- data/lib/generators/dynamic_scaffold/templates/controller.erb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a34161c9b0f492dc373a6d627c7d9fe92e7d5e029f7d38b6a297a4745194d61
|
4
|
+
data.tar.gz: 7b24882b15fff9bb0ff8498d9dfb7382560a68f1ff3710a7122dafe7f8376e01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9637909fe95e58cdd6a57f08552b68a3abbb666b0693dad54c524ac2a7ea9eb5bf0e87646497f678f4b878e91c629d5ed46e6212c8046c3ed2662f54306dbc21
|
7
|
+
data.tar.gz: de85a41e741a08e258062d3e8917ea1fafb41c66643bfd631dac4882c449577ab5baf111d3dcdc3c60ce860e44f59029b80e4c35d20f2a509435f491c698e418
|
data/README.md
CHANGED
@@ -225,7 +225,7 @@ class ShopController < ApplicationController
|
|
225
225
|
:category_id, Category.all, :id, :name, include_blank: 'Select Category'
|
226
226
|
)
|
227
227
|
config.form.item(:collection_check_boxes, :state_ids, State.all, :id, :name)
|
228
|
-
config.form.item(:collection_radio_buttons, :status, Shop.statuses.map{|k,
|
228
|
+
config.form.item(:collection_radio_buttons, :status, Shop.statuses.map{|k, _v| [k, k.titleize]}, :first, :last)
|
229
229
|
|
230
230
|
# If you want to display more free form field, use block.
|
231
231
|
# The block is executed in the context of view, so you can call the method of view.
|
@@ -242,6 +242,18 @@ class ShopController < ApplicationController
|
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
+
# You can insert HTML before/after the element.
|
246
|
+
config.form.item(:file_field, :image).label('Image').insert(:after) do |rec|
|
247
|
+
tag.label for: :delete_image do
|
248
|
+
concat tag.input type: :checkbox, id: :delete_image, name: 'shop[delete_image]'
|
249
|
+
concat 'Delete image'
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
# You need to permit the new form parameters you inserted.
|
254
|
+
# And if necessary, add virtual attributes to the model.
|
255
|
+
config.form.permit_params(:delete_image)
|
256
|
+
|
245
257
|
# You can also add a note to the form field.
|
246
258
|
config.form.item(:text_field, :name).note do
|
247
259
|
content_tag :p do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= form_with method: method, model: @record, url: url, local: true do |form| %>
|
2
|
-
|
2
|
+
<%-dynamic_scaffold.form.items.each do |elem|-%>
|
3
3
|
<% if elem.needs_rendering?(self)%>
|
4
4
|
<% if !elem.label? && elem.type?(:hidden_field) %>
|
5
5
|
<%= elem.render(self, form) %>
|
@@ -7,6 +7,9 @@
|
|
7
7
|
<div class="<%= class_names('form-group', {'has-error': @record.errors[elem.proxy_field.name].any?}) %>">
|
8
8
|
<label><%= elem.proxy_field.label %></label>
|
9
9
|
<div class="clearfix">
|
10
|
+
<%- elem.insert(:before).each do |block| -%>
|
11
|
+
<%= self.instance_exec(@record, &block) %>
|
12
|
+
<%-end-%>
|
10
13
|
<% if elem.type? :collection_check_boxes %>
|
11
14
|
<%= elem.render(self, form) do |cb|%>
|
12
15
|
<div class="form-check checkbox">
|
@@ -26,6 +29,9 @@
|
|
26
29
|
<% else %>
|
27
30
|
<%= elem.render(self, form, class_names('form-control', {'is-invalid': @record.errors[elem.proxy_field.name].any?})) %>
|
28
31
|
<% end %>
|
32
|
+
<%- elem.insert(:after).each do |block| -%>
|
33
|
+
<%= self.instance_exec(@record, &block) %>
|
34
|
+
<%-end-%>
|
29
35
|
</div>
|
30
36
|
<%if @record.errors[elem.proxy_field.name].any?%>
|
31
37
|
<ul class="dynamicScaffold-error-message">
|
@@ -214,6 +214,7 @@ module DynamicScaffold
|
|
214
214
|
def initialize(config)
|
215
215
|
@config = config
|
216
216
|
@items = []
|
217
|
+
@permit_params = []
|
217
218
|
end
|
218
219
|
|
219
220
|
def items
|
@@ -227,6 +228,15 @@ module DynamicScaffold
|
|
227
228
|
@items
|
228
229
|
end
|
229
230
|
|
231
|
+
def permit_params(*params)
|
232
|
+
if !params.empty?
|
233
|
+
@permit_params.concat(params)
|
234
|
+
self
|
235
|
+
else
|
236
|
+
@permit_params
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
230
240
|
def item(type, *args, &block) # rubocop:disable Metrics/MethodLength
|
231
241
|
case type
|
232
242
|
when
|
@@ -58,11 +58,10 @@ module DynamicScaffold
|
|
58
58
|
|
59
59
|
def create
|
60
60
|
@record = dynamic_scaffold.model.new
|
61
|
-
prev_attribute = @record.attributes
|
62
61
|
@record.attributes = update_values
|
63
62
|
bind_sorter_value(@record) if dynamic_scaffold.list.sorter
|
64
63
|
dynamic_scaffold.model.transaction do
|
65
|
-
yield(@record
|
64
|
+
yield(@record) if block_given?
|
66
65
|
if @record.save
|
67
66
|
redirect_to dynamic_scaffold_path(:index)
|
68
67
|
else
|
@@ -30,9 +30,10 @@ module DynamicScaffold
|
|
30
30
|
|
31
31
|
# Get paramters for update record.
|
32
32
|
def update_values
|
33
|
+
permitting = dynamic_scaffold.form.items.map(&:strong_parameter).concat(dynamic_scaffold.form.permit_params)
|
33
34
|
values = params
|
34
35
|
.require(dynamic_scaffold.model.name.underscore)
|
35
|
-
.permit(*
|
36
|
+
.permit(*permitting)
|
36
37
|
|
37
38
|
if dynamic_scaffold.scope && !valid_for_scope?(values)
|
38
39
|
raise DynamicScaffold::Error::Controller, "You can update only to #{scope_params} on this scope"
|
@@ -13,6 +13,10 @@ module DynamicScaffold
|
|
13
13
|
@classnames_list.push(classnames) if classnames
|
14
14
|
@notes = []
|
15
15
|
@multiple = type == :collection_check_boxes || html_attributes[:multiple]
|
16
|
+
@inserts = {
|
17
|
+
before: [],
|
18
|
+
after: []
|
19
|
+
}
|
16
20
|
end
|
17
21
|
|
18
22
|
def notes?
|
@@ -91,6 +95,15 @@ module DynamicScaffold
|
|
91
95
|
@default = value
|
92
96
|
end
|
93
97
|
|
98
|
+
def insert(position, &block)
|
99
|
+
if block_given?
|
100
|
+
@inserts[position] << block
|
101
|
+
self
|
102
|
+
else
|
103
|
+
@inserts[position]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
94
107
|
protected
|
95
108
|
|
96
109
|
def build_html_attributes(classnames)
|
@@ -79,7 +79,7 @@ class <%= @class_scope.present? ? "#{@class_scope}::" : '' %><%= @plural_model_n
|
|
79
79
|
# end
|
80
80
|
|
81
81
|
# def create
|
82
|
-
# super do |record
|
82
|
+
# super do |record|
|
83
83
|
# # If you want to modify the attributes of the record before saving, Write here.
|
84
84
|
# end
|
85
85
|
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masamoto Miyata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: classnames-rails-view
|