diff options
| author | mo k <mo@mokhan.ca> | 2012-10-06 17:08:06 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-10-06 17:08:06 -0600 |
| commit | 2cfcf1ea33798625541c8aeafc83e5e438b58c1d (patch) | |
| tree | d11540e757772c2a59c2fff027daa6bfc28504a3 | |
| parent | 0256a2e383741c2dba0114316526eb014daeeff5 (diff) | |
move creation of a creation logic into the user model.
| -rw-r--r-- | app/controllers/creations_controller.rb | 23 | ||||
| -rw-r--r-- | app/models/user.rb | 7 |
2 files changed, 21 insertions, 9 deletions
diff --git a/app/controllers/creations_controller.rb b/app/controllers/creations_controller.rb index bf42246b..ebe1c526 100644 --- a/app/controllers/creations_controller.rb +++ b/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 diff --git a/app/models/user.rb b/app/models/user.rb index 540a2ce6..4492ce13 100644 --- a/app/models/user.rb +++ b/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 |
