Class: Eboshi::AssignmentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/eboshi/assignments_controller.rb

Instance Method Summary collapse

Methods included from ShallowRouteHelper

#assignment_path, #assignments_path, #convert_work_path, #edit_adjustment_path, #edit_invoice_path, #edit_work_path, #invoice_path, #invoices_path, #line_item_path, #merge_works_path, #new_adjustment_path, #new_assignment_path, #new_invoice_path, #new_payment_path, #payments_path, #work_path

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/eboshi/assignments_controller.rb', line 8

def create
  @client = current_user.clients.find params[:client_id]
  user = User.find_by_id(params[:assignment][:user_id]) || User.find_by_email(params[:assignment][:email])
  if user
    @client.users << user
    redirect_to invoices_path(@client), notice: "Successfully created!"
  else
    redirect_to({ action: :new }, alert: "A user with that email address does not exist!")
  end
end

#destroyObject

Raises:

  • (ActiveRecord::RecordNotFound)


19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/eboshi/assignments_controller.rb', line 19

def destroy
  @assignment = Assignment.find params[:id]
  raise ActiveRecord::RecordNotFound unless current_user.clients.include? @assignment.client
  @assignment.destroy
  if @assignment.user == current_user
    redirect_to "/"
  else
    redirect_back fallback_location: "/"
  end
end

#newObject



3
4
5
6
# File 'app/controllers/eboshi/assignments_controller.rb', line 3

def new
  @client = current_user.clients.find params[:client_id]
  @assignment = @client.assignments.build user: current_user
end