Commit 2cfcf1ea

mo k <mo@mokhan.ca>
2012-10-06 23:08:06
move creation of a creation logic into the user model.
1 parent 0256a2e
Changed files (2)
app/controllers/creations_controller.rb
@@ -23,15 +23,20 @@ class CreationsController < ApplicationController
 
   # POST /creations
   def create
-    @creation = current_user.creations.create(params[:creation])
-    @creation.category_ids = params[:creation][:category_ids] ||= []
-    if @creation.save
-      #redirect_to( '/creations/crop/' + @creation.id.to_s ) 
-      redirect_to(@creation, :notice => 'Creation was successfully cropped.') 
-    else
-      flash[:error] = @creation.errors.full_messages
-      render :action => "new" 
-    end
+    #@creation = current_user.creations.create(params[:creation])
+    #@creation.category_ids = params[:creation][:category_ids] ||= []
+
+    #if @creation.save
+      ##redirect_to( '/creations/crop/' + @creation.id.to_s ) 
+      #Rails.logger.info "end create"
+      #redirect_to(@creation, :notice => 'Creation was successfully cropped.') 
+    #else
+      #flash[:error] = @creation.errors.full_messages
+      #render :action => "new" 
+    #end
+
+    @creation = current_user.add_creation(params[:creation])
+    redirect_to(@creation, :notice => 'Creation was successfully cropped.') 
   end
 
   # PUT /creations/1
app/models/user.rb
@@ -32,6 +32,13 @@ class User < ActiveRecord::Base
     Comment.create_for(self, creation, comment)
   end
 
+  def add_creation(params)
+    @creation = creations.create(params)
+    @creation.category_ids = params[:category_ids] ||= []
+    @creation.save!
+    @creation
+  end
+
   def to_param
     "#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
   end