Skip to content
Browse files

no need to load Conversation just to delete it

  • Loading branch information...
1 parent 3ef5371 commit c3910059ed2e78e0ca1d866b371e890252bf1133 @tomcz tomcz committed Mar 15, 2010
View
4 app/controllers/products_controller.rb
@@ -60,7 +60,7 @@ def create
if product.save
flash[:notice] = 'Product was successfully created.'
format.html {
- Conversation.destroy_if_exists(params[:conversation_id])
+ Conversation.delete_if_exists(params[:conversation_id])
redirect_to(product)
}
format.xml { render :xml => product, :status => :created, :location => product }
@@ -84,7 +84,7 @@ def update
if product.update_attributes(params[:product])
flash[:notice] = 'Product was successfully updated.'
format.html {
- Conversation.destroy_if_exists(params[:conversation_id])
+ Conversation.delete_if_exists(params[:conversation_id])
redirect_to(product)
}
format.xml { head :ok }
View
2 app/controllers/store_controller.rb
@@ -39,7 +39,7 @@ def save_order
@order.add_line_items_from_cart(@cart)
if @order.save
session[:cart] = nil
- Conversation.destroy_if_exists(params[:id])
+ Conversation.delete_if_exists(params[:id])
redirect_to_index("Thank you for your order")
else
conversation = Conversation.get_or_create(params[:id])
View
4 app/controllers/users_controller.rb
@@ -60,7 +60,7 @@ def create
if @user.save
flash[:notice] = "User #{@user.name} was successfully created."
format.html {
- Conversation.destroy_if_exists(params[:conversation_id])
+ Conversation.delete_if_exists(params[:conversation_id])
redirect_to :action=>'index'
}
format.xml { render :xml => @user, :status => :created, :location => @user }
@@ -84,7 +84,7 @@ def update
if @user.update_attributes(params[:user])
flash[:notice] = "User #{@user.name} was successfully updated."
format.html {
- Conversation.destroy_if_exists(params[:conversation_id])
+ Conversation.delete_if_exists(params[:conversation_id])
redirect_to :action=>'index'
}
format.xml { head :ok }
View
5 app/models/conversation.rb
@@ -17,10 +17,9 @@ def self.get_or_create(uuid)
end
end
- def self.destroy_if_exists(uuid)
+ def self.delete_if_exists(uuid)
unless uuid.to_s == 'new'
- conversation = self.find_by_uuid(uuid)
- conversation.destroy if conversation
+ Conversation.delete uuid
end
end

0 comments on commit c391005

Please sign in to comment.
Something went wrong with that request. Please try again.