osem-fcy/app/controllers/organizations_controller.rb

41 lines
1,004 B
Ruby
Raw Normal View History

class OrganizationsController < ApplicationController
2017-05-31 19:35:43 +05:30
load_and_authorize_resource :organization
2017-05-31 19:35:43 +05:30
def index
@organizations = Organization.all
end
2017-05-31 19:35:43 +05:30
def create
@organization = Organization.new(organization_params)
if @organization.save
redirect_to organizations_path,
notice: 'Organization successfully created'
else
redirect_to new_organization_path,
error: @organization.errors.full_messages.join(', ')
end
end
2017-05-31 19:35:43 +05:30
def new
@organization = Organization.new
end
2017-05-31 19:35:43 +05:30
def edit; end
2017-05-31 19:35:43 +05:30
def update
if @organization.update_attributes(organization_params)
redirect_to organizations_path,
notice: 'Organization successfully updated'
else
redirect_to edit_organization_path(@organization),
error: @organization.errors.full_messages.join(', ')
end
end
2017-05-31 19:35:43 +05:30
private
2017-05-31 19:35:43 +05:30
def organization_params
params.require(:organization).permit(:name, :description, :picture)
end
end