action-draft 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +44 -6
- data/lib/action-draft/attribute.rb +1 -6
- data/lib/action-draft/version.rb +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: 9c0afd25033b0008a527ef5e4a551ce02e70adc96ab791c5ef24a509a7c78c21
|
4
|
+
data.tar.gz: 97b7b7fe0774cd5cef52aa90356bb5b2d954137a320fd63f14516ca824b9aa71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a77485d2e4266cda492f869b1b4b7d840b42a9290fb2772d76ba4d9723be52f55ed5f86a9758fcc9a25691ecfb2b90c98bb0990e95cb82b1eae798e0b6b00ead
|
7
|
+
data.tar.gz: 24185b22f7f7801ff063ec3d0283e63d375d20dca0a4e4407a60c287b9458c37e9b89a8902febbd491cae26d24b7ac4e59c63a70fdff58e91b02c72e5b46cee7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Action Draft brings your ActiveRecord model to storage multiple draft attributes
|
|
8
8
|
|
9
9
|
- Save drafts without add columns to the business table.
|
10
10
|
- Work any ActiveRecord model, just add `has_draft :field_name`.
|
11
|
-
- A `
|
11
|
+
- A `apply_draft` method for assignment the draft values to actual attributes.
|
12
12
|
- Fallback to actual attribute value when draft is nil.
|
13
13
|
|
14
14
|
## Installation
|
@@ -55,6 +55,45 @@ Then refer to this field in the form for the model:
|
|
55
55
|
<% end %>
|
56
56
|
```
|
57
57
|
|
58
|
+
In your controller
|
59
|
+
|
60
|
+
```rb
|
61
|
+
class MessagesController < ApplicationController
|
62
|
+
def new
|
63
|
+
@message = Message.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def create
|
67
|
+
@message = Message.new(message_params)
|
68
|
+
message.apply_draft if message_params[:publish]
|
69
|
+
if message.save
|
70
|
+
redirect_to messages_path, notice: "Message has created successfully"
|
71
|
+
else
|
72
|
+
render :new
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def update
|
77
|
+
@message.assign_attributes(message_params)
|
78
|
+
message.apply_draft if message_params[:publish]
|
79
|
+
if message.save
|
80
|
+
redirect_to messages_path, notice: "Message has updated successfully"
|
81
|
+
else
|
82
|
+
render :edit
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def set_message
|
88
|
+
@message = Message.find(params[:id])
|
89
|
+
end
|
90
|
+
|
91
|
+
def message_params
|
92
|
+
params.require(:message).perrmit(:draft_title, :draft_content, :publish)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
58
97
|
Save draft attributes:
|
59
98
|
|
60
99
|
```rb
|
@@ -67,26 +106,25 @@ irb> message.draft_content.to_s
|
|
67
106
|
"Draft message content"
|
68
107
|
irb> message.save
|
69
108
|
|
70
|
-
|
109
|
+
irb> message.reload
|
71
110
|
irb> message.draft_title.to_s
|
72
111
|
"Draft title"
|
73
112
|
irb> message.draft_content.to_s
|
74
113
|
"Draft message content"
|
75
114
|
```
|
76
115
|
|
77
|
-
|
116
|
+
Apply draft content:
|
78
117
|
|
79
118
|
```rb
|
80
119
|
irb> message = Message.new
|
81
120
|
irb> message.draft_title = "Message title"
|
82
|
-
irb> message.
|
121
|
+
irb> message.apply_draft
|
83
122
|
|
84
|
-
irb> message.new_record?
|
85
|
-
false
|
86
123
|
irb> message.title
|
87
124
|
"Message title"
|
88
125
|
irb> message.draft_title
|
89
126
|
"Message title"
|
127
|
+
irb> message.save
|
90
128
|
```
|
91
129
|
|
92
130
|
## License
|
@@ -8,16 +8,11 @@ module ActionDraft
|
|
8
8
|
mattr_accessor :action_draft_attributes
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def apply_draft
|
12
12
|
self.action_draft_attributes ||= []
|
13
13
|
self.action_draft_attributes.each do |_name|
|
14
14
|
self.send("#{_name}=", self.send("draft_#{_name}").to_s)
|
15
15
|
end
|
16
|
-
self.save
|
17
|
-
end
|
18
|
-
|
19
|
-
def publish!
|
20
|
-
publish ? true : raise_validation_error
|
21
16
|
end
|
22
17
|
|
23
18
|
class_methods do
|
data/lib/action-draft/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-draft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|