2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
18 # handles CRUD on Organization records
19 class Objects::OrganizationController < ObjectsController
22 @organizations, @total_pages = smr_paginate(
24 Organization.all.order(:name).to_a
29 # defines empty Organization to create() a new one
32 @organization = Organization.new
37 # edit existing Organization
40 @organization = Organization.where(:id=>params[:id]).first
45 # handles creates and updates
47 if params[:organization][:id].to_i > 0 then
48 o = Organization.where(:id=>params[:organization][:id]).first
49 else o = Organization.new(organization_params) end
51 # hard-wired so noone spoofes it in here
52 # FIXME: how to handle properly? given 0 _or_ current user id
53 # fv.id_user = current_user.id
55 if params[:organization][:id].to_i > 0 then
56 o.update(organization_params)
59 redirect_to objects_organization_index_path, :notice=>o.errors.full_messages.uniq.join(', ')
65 # internal helper defining parameters acceptable for Organization create/update
66 def organization_params
67 params.require(:organization).permit(
68 :name, :url, :contact_email, :description,