Class: Ncr::ProposalsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ncr/proposals_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/ncr/proposals_controller.rb', line 14

def create
  @proposal_form = Ncr::ProposalForm.new(params[:ncr_proposal])
  @proposal_form.requester = current_user
  if @proposal_form.valid?
    cart = @proposal_form.create_cart
    if cart.persisted?
      Dispatcher.deliver_new_cart_emails(cart)
      flash[:success] = "Proposal submitted!"
      redirect_to cart_path(cart)
    else
      flash[:error] = cart.errors.full_messages
      render 'new'
    end
  else
    flash[:error] = @proposal_form.errors.full_messages
    render 'new'
  end
end

#newObject


5
6
7
8
9
10
11
12
# File 'app/controllers/ncr/proposals_controller.rb', line 5

def new
  @proposal_form = Ncr::ProposalForm.new
  last_cart = current_user.last_requested_cart
  if last_cart
    approver = last_cart.approvers.first
    @proposal_form.approver_email = approver.try(:email_address)
  end
end