action-draft 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fde164f418f2264692ee13820be77814869782461b521635871c132946f4e74
4
- data.tar.gz: 206426857fa67eac4317bf72747a7517c8fe15097308c1620b790c044fbd1a88
3
+ metadata.gz: 9c0afd25033b0008a527ef5e4a551ce02e70adc96ab791c5ef24a509a7c78c21
4
+ data.tar.gz: 97b7b7fe0774cd5cef52aa90356bb5b2d954137a320fd63f14516ca824b9aa71
5
5
  SHA512:
6
- metadata.gz: 7f39f613f05c12f53448f5e17ed92bc68866db93840e937390384b52b86ec5895509a0a0d626e341ae13642fcad182f9866ca85091ab0710fd60ba64a8627c64
7
- data.tar.gz: 596647366cde77653b62189c50bb86ce12aa462ddc2e06b840882e12e36382c1620f96fe7ffe31ca6255202a6bfaceb688b979382ed1717bbfcb79600d191e19
6
+ metadata.gz: a77485d2e4266cda492f869b1b4b7d840b42a9290fb2772d76ba4d9723be52f55ed5f86a9758fcc9a25691ecfb2b90c98bb0990e95cb82b1eae798e0b6b00ead
7
+ data.tar.gz: 24185b22f7f7801ff063ec3d0283e63d375d20dca0a4e4407a60c287b9458c37e9b89a8902febbd491cae26d24b7ac4e59c63a70fdff58e91b02c72e5b46cee7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.3.0
2
+ -----
3
+
4
+ - Remove `publish`, instead of use `apply_draft` without save record.
5
+
1
6
  0.2.0
2
7
  -----
3
8
 
@@ -7,4 +12,4 @@
7
12
  0.1.0
8
13
  -----
9
14
 
10
- First commit.
15
+ First commit.
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 `publish` method for assignment the draft values to actual attributes.
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
- ir> message.reload
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
- Publish draft content:
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.publish
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 publish
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionDraft
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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.2.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-25 00:00:00.000000000 Z
11
+ date: 2019-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails