we_bridge-auto_view_helper 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9408085ceb7907955e8bdca4951cd50e216821d0
|
4
|
+
data.tar.gz: fad421b8ed9e532246df66b2e570a2a891473324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0f019dcf3360713080b5a16117f3541923b69160645ccd6be976edf8c166bc401de4ce2dcc3354d1df6ae52cf246a5d6765472317519133d6632ec725a06863
|
7
|
+
data.tar.gz: 87053fe753c752998b3c1d0afc409c4c9fa3cf60b492375c4ad0ce11722291bcb3ee546ba786d38f6bbb182f1ed8ac05bb3a2bd3eb7aa725d5f19e6bc623b03e
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module WeBridge
|
2
|
+
module AutoViewHelper
|
3
|
+
module Controller
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def set_model(model) @model = model; end
|
7
|
+
|
8
|
+
def model() @model; end
|
9
|
+
|
10
|
+
def pathinfo() @pathinfo ||= {}; end
|
11
|
+
|
12
|
+
def set_pathinfo(pathinfo) (@pathinfo ||= {}).merge(pathinfo); end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(base)
|
16
|
+
base.extend ClassMethods
|
17
|
+
base.before_action :set_record, only: [:show, :edit, :update, :destroy]
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /???s
|
21
|
+
def index
|
22
|
+
@records = self.class.model.all
|
23
|
+
end
|
24
|
+
|
25
|
+
# GET /???s/1
|
26
|
+
def show
|
27
|
+
end
|
28
|
+
|
29
|
+
# GET /???s/new
|
30
|
+
def new
|
31
|
+
@record = self.class.model.new
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET /???s/1/edit
|
35
|
+
def edit
|
36
|
+
end
|
37
|
+
|
38
|
+
# POST /???s
|
39
|
+
def create
|
40
|
+
@record = self.class.model.new(record_params)
|
41
|
+
@record.class.transaction do
|
42
|
+
@record.save!
|
43
|
+
record_text_params.try :each do |code,text_params|
|
44
|
+
text = @record.text(code)
|
45
|
+
text.attributes = text_params
|
46
|
+
text.save!
|
47
|
+
end
|
48
|
+
flash[:notice] = 'Record was successfully created.'
|
49
|
+
redirect_to action: :show, id: @record.id
|
50
|
+
end
|
51
|
+
rescue
|
52
|
+
redirect_to action: :new
|
53
|
+
end
|
54
|
+
|
55
|
+
# PATCH/PUT /???s/1
|
56
|
+
def update
|
57
|
+
@record.class.transaction do
|
58
|
+
@record.update!(record_params)
|
59
|
+
record_text_params.try :each do |code,text_params|
|
60
|
+
text = @record.text(code)
|
61
|
+
text.attributes = text_params
|
62
|
+
text.save!
|
63
|
+
end
|
64
|
+
flash[:notice]='Record was successfully updated.'
|
65
|
+
redirect_to action: :show, id: @record.id
|
66
|
+
end
|
67
|
+
rescue
|
68
|
+
redirect_to action: :edit, id: @record.id
|
69
|
+
end
|
70
|
+
|
71
|
+
# DELETE /???s/1
|
72
|
+
def destroy
|
73
|
+
@record.destroy
|
74
|
+
flash[:notice]= 'Record was successfully destroyed.'
|
75
|
+
redirect_to action: :index
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
# Use callbacks to share common setup or constraints between actions.
|
80
|
+
def set_record
|
81
|
+
@record = self.class.model.find(params[:id])
|
82
|
+
end
|
83
|
+
|
84
|
+
# Only allow a trusted parameter "white list" through.
|
85
|
+
def record_params
|
86
|
+
params.require(self.class.model.table_name).permit(*self.class.model.editable_columns)
|
87
|
+
end
|
88
|
+
|
89
|
+
def record_text_params
|
90
|
+
columns = self.class.model.text.editable_columns
|
91
|
+
permit = Hash[*self.class.model.all.pluck(:code).map{|code| [code,columns] }.flatten(1)]
|
92
|
+
params[self.class.model.text.table_name].try(:permit,permit)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: we_bridge-auto_view_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinjiro Itagaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bin/console
|
114
114
|
- bin/setup
|
115
115
|
- lib/we_bridge/auto_view_helper.rb
|
116
|
+
- lib/we_bridge/auto_view_helper/controller.rb
|
116
117
|
- lib/we_bridge/auto_view_helper/version.rb
|
117
118
|
- we_bridge-auto_view_helper.gemspec
|
118
119
|
homepage: https://github.com/baseball-bridge/we_bridge-auto_view_helper
|