Commit 8002091d authored by Maxwell Salzberg's avatar Maxwell Salzberg

kinda refactor another sucky controller method

parent cc5334ce
......@@ -10,22 +10,16 @@ class AspectsController < ApplicationController
:json
def create
@aspect = current_user.aspects.create(params[:aspect])
@aspect = current_user.aspects.build(params[:aspect])
aspecting_person_id = params[:aspect][:person_id]
if @aspect.valid?
if @aspect.save
flash[:notice] = I18n.t('aspects.create.success', :name => @aspect.name)
if current_user.getting_started
redirect_to :back
elsif request.env['HTTP_REFERER'].include?("contacts")
redirect_to :back
elsif params[:aspect][:person_id].present?
@person = Person.where(:id => params[:aspect][:person_id]).first
if @contact = current_user.contact_for(@person)
@contact.aspects << @aspect
else
@contact = current_user.share_with(@person, @aspect)
end
if current_user.getting_started || request.referer.include?("contacts")
redirect_to :back
elsif aspecting_person_id.present?
connect_person_to_aspect(aspecting_person_id)
else
redirect_to contacts_path(:a_id => @aspect.id)
end
......@@ -40,6 +34,16 @@ class AspectsController < ApplicationController
end
end
#person_id, user, @aspect
def connect_person_to_aspect(aspecting_person_id)
@person = Person.find(aspecting_person_id)
if @contact = current_user.contact_for(@person)
@contact.aspects << @aspect
else
@contact = current_user.share_with(@person, @aspect)
end
end
def new
@aspect = Aspect.new
@person_id = params[:person_id]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment