@@ -106,25 +106,17 @@ def create
106
106
# PATCH/PUT /stories/1
107
107
# PATCH/PUT /stories/1.json
108
108
def update
109
- respond_to do |format |
110
- # NOTE: To avoid DEPRECATION WARNING when saving with Globalize attributes
111
- # wait for this pull request to be merged https://github.com/globalize/globalize/pull/629
109
+ # NOTE: To avoid DEPRECATION WARNING when saving with Globalize attributes
110
+ # wait for this pull request to be merged https://github.com/globalize/globalize/pull/629
112
111
113
- # Temporary change I18n.locale for saving the Story using @story_locale
114
- current_locale = I18n . locale
115
- I18n . locale = @story_locale
116
- if @story . update ( story_params )
117
- @story . images << images_from_content ( @story )
118
- # I18n.locale back to the original
119
- I18n . locale = current_locale
120
- format . html { redirect_to story_path ( @story , story_locale : @story_locale ) , notice : _ ( 'Story was successfully updated.' ) }
121
- format . json { render :show , status : :ok , location : @story }
122
- else
123
- # I18n.locale back to the original
124
- I18n . locale = current_locale
125
- format . html { render :edit }
126
- format . json { render json : @story . errors , status : :unprocessable_entity }
127
- end
112
+ # Temporary change I18n.locale for saving the Story using @story_locale
113
+ current_locale = I18n . locale
114
+ I18n . locale = @story_locale
115
+
116
+ if params [ :story_builder ] == 'true'
117
+ update_with_story_builder ( current_locale )
118
+ else
119
+ update_with_text_content ( current_locale )
128
120
end
129
121
end
130
122
@@ -139,6 +131,9 @@ def destroy
139
131
end
140
132
141
133
def publish
134
+ # set params without saving (used only for anonymous)
135
+ @story . assign_attributes ( publish_params )
136
+
142
137
if @story . publish!
143
138
respond_to do |format |
144
139
format . html { redirect_to @story }
@@ -183,9 +178,25 @@ def create_with_story_builder(restore_locale)
183
178
end
184
179
end
185
180
181
+ def update_with_story_builder ( restore_locale )
182
+ if @story . update ( story_params )
183
+ # I18n.locale back to the original
184
+ I18n . locale = restore_locale
185
+ respond_to do |format |
186
+ format . json { render :show , status : :ok , location : @story }
187
+ end
188
+ else
189
+ # I18n.locale back to the original
190
+ I18n . locale = restore_locale
191
+ respond_to do |format |
192
+ format . json { render json : @story . errors , status : :unprocessable_entity }
193
+ end
194
+ end
195
+ end
196
+
186
197
# creates a story with a text content
187
198
def create_with_text_content ( restore_locale )
188
- if @story . save
199
+ if @story . save && @story . publish!
189
200
@story . images << images_from_content ( @story )
190
201
I18n . locale = restore_locale
191
202
respond_to do |format |
@@ -199,6 +210,23 @@ def create_with_text_content(restore_locale)
199
210
end
200
211
end
201
212
213
+ def update_with_text_content ( restore_locale )
214
+ if @story . update ( story_params ) && @story . publish!
215
+ @story . images << images_from_content ( @story )
216
+ # I18n.locale back to the original
217
+ I18n . locale = restore_locale
218
+ respond_to do |format |
219
+ format . html { redirect_to story_path ( @story , story_locale : @story_locale ) , notice : _ ( 'Story was successfully updated.' ) }
220
+ end
221
+ else
222
+ # I18n.locale back to the original
223
+ I18n . locale = restore_locale
224
+ respond_to do |format |
225
+ format . html { render :edit }
226
+ end
227
+ end
228
+ end
229
+
202
230
# This method creates the not-yet-existing tags and replaces
203
231
# tag_ids with their ids.
204
232
def create_new_tags
@@ -236,4 +264,8 @@ def set_draft_params(pars)
236
264
pars [ :story ] [ :content_json_draft ] = pars [ :story ] [ :content_json ]
237
265
pars [ :story ] [ :place_draft ] = pars [ :story ] [ :place ]
238
266
end
267
+
268
+ def publish_params
269
+ params . permit ( :anonymous )
270
+ end
239
271
end
0 commit comments