Refactored code so that the controller got thinner while the model become fatter [Finishes #1126]
This commit is contained in:
parent
2947ee46f4
commit
f8f1ef3f91
2 changed files with 10 additions and 6 deletions
|
|
@ -127,13 +127,8 @@ class PhotosController < ApplicationController
|
||||||
format.json{ render :nothing => true, :status => 204 }
|
format.json{ render :nothing => true, :status => 204 }
|
||||||
format.html do
|
format.html do
|
||||||
flash[:notice] = I18n.t 'photos.destroy.notice'
|
flash[:notice] = I18n.t 'photos.destroy.notice'
|
||||||
if photo.status_message_guid
|
if StatusMessage.find_by_guid(photo.status_message_guid)
|
||||||
if photo.status_message.text_and_photos_blank?
|
|
||||||
photo.status_message.destroy
|
|
||||||
respond_with photo, :location => person_photos_path(current_user.person)
|
|
||||||
else
|
|
||||||
respond_with photo, :location => post_path(photo.status_message)
|
respond_with photo, :location => post_path(photo.status_message)
|
||||||
end
|
|
||||||
else
|
else
|
||||||
respond_with photo, :location => person_photos_path(current_user.person)
|
respond_with photo, :location => person_photos_path(current_user.person)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,17 @@ class Photo < Post
|
||||||
validate :ownership_of_status_message
|
validate :ownership_of_status_message
|
||||||
|
|
||||||
before_destroy :ensure_user_picture
|
before_destroy :ensure_user_picture
|
||||||
|
after_destroy :clear_empty_status_message
|
||||||
after_create :queue_processing_job
|
after_create :queue_processing_job
|
||||||
|
|
||||||
|
def clear_empty_status_message
|
||||||
|
if self.status_message_guid && self.status_message.text_and_photos_blank?
|
||||||
|
self.status_message.destroy
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def ownership_of_status_message
|
def ownership_of_status_message
|
||||||
message = StatusMessage.find_by_guid(self.status_message_guid)
|
message = StatusMessage.find_by_guid(self.status_message_guid)
|
||||||
if self.status_message_guid && message
|
if self.status_message_guid && message
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue