Skip to content
Extraits de code Groupes Projets
Valider c8a88495 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Move to build_post and dispatch_post in most controllers

parent a08fa769
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -14,15 +14,17 @@ class AlbumsController < ApplicationController
end
def create
aspect = params[:album][:to]
aspects = params[:album][:to]
@album = current_user.post(:album, params[:album])
if @album.persisted?
@album = current_user.build_post(:album, params[:album])
if @album.save
raise 'MongoMapper failed to catch a failed save' unless @album.id
current_user.dispatch_post(@album, :to => aspects)
flash[:notice] = I18n.t 'albums.create.success', :name => @album.name
redirect_to :action => :show, :id => @album.id, :aspect => aspect
redirect_to :action => :show, :id => @album.id, :aspect =>aspects
else
flash[:error] = I18n.t 'albums.create.failure'
redirect_to albums_path(:aspect => aspect)
redirect_to albums_path(:aspect =>aspects)
end
end
......
......@@ -56,9 +56,8 @@ class DevUtilitiesController < ApplicationController
def set_profile_photo
render :nothing => true
album = current_user.post(:album, :name => "Profile Photos", :to => current_user.aspects.first.id)
current_user.raw_visible_posts << album
current_user.save
album = current_user.build_post(:album, :name => "Profile Photos")
current_user.dispatch_post(album, :to => current_user.aspects.first.id)
backer_number = YAML.load_file(Rails.root.join('config','backer_number.yml'))[:seed_number].to_i
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
......
......@@ -49,10 +49,16 @@ class PhotosController < ApplicationController
params[:photo][:user_file] = file
@photo = current_user.post(:photo, params[:photo])
respond_to do |format|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
raise 'MongoMapper failed to catch a failed save' unless post.id
current_user.dispatch_post(@photo, :to => params[:photo][:to])
respond_to do |format|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
end
else
respond_with :location => album, :error => message
end
rescue TypeError
......
......@@ -13,7 +13,11 @@ class StatusMessagesController < ApplicationController
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
params[:status_message][:public] = public_flag
status_message = current_user.post(:status_message, params[:status_message])
status_message = current_user.build_post(:status_message, params[:status_message])
if status_message.save(:safe => true)
raise 'MongoMapper failed to catch a failed save' unless status_message.id
current_user.dispatch_post(status_message, :to => params[:status_message][:to])
end
render :nothing => true
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter