Class: OrganizationsController

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

Overview

Manges requests to view and manipulate Organization objects

See Also:

Instance Method Summary collapse

Instance Method Details

#createObject

POST /organizations



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/organizations_controller.rb', line 25

def create
  self.current_organization = Organization.create(organization_params)

  if current_organization.valid?
    current_organization.memberships.owner.create!(user: current_user)
    logger.info "Created #{current_organization} and assigned #{current_user}"
    redirect_to current_organization, success: "Created #{current_organization.title}"
  else
    logger.warn "Unable to create Organization: #{current_organization.error_sentence}"
    flash.now[:alert] = "There was an error creating this Organization"
    render action: "new"
  end
end

#editObject

GET /organizations/1/edit



40
41
# File 'app/controllers/organizations_controller.rb', line 40

def edit
end

#indexObject

GET /organizations



11
12
13
# File 'app/controllers/organizations_controller.rb', line 11

def index
  self.organizations = current_user.organizations
end

#newObject

GET /organizations/new



20
21
22
# File 'app/controllers/organizations_controller.rb', line 20

def new
  self.current_organization = Organization.new
end

#showObject

GET /organizations/1



16
17
# File 'app/controllers/organizations_controller.rb', line 16

def show
end

#updateObject

PATCH /organizations/1



44
45
46
47
48
49
50
51
# File 'app/controllers/organizations_controller.rb', line 44

def update
  if current_organization.update_attributes(organization_params)
    redirect_to current_organization, success: "Saved changes to #{current_organization.title}"
  else
    flash.now[:alert] = "There was an error updating this Organization"
    render action: "edit"
  end
end