class OrganizationsController < ApplicationController before_action :set_organization, only: [:show, :edit, :update, :destroy] before_filter :require_login, :except => [:index, :show] # GET /organizations def index @organizations = Organization.all end # GET /organizations/1 def show end # GET /organizations/new def new @organization = Organization.new #@organization.location = Location.new @organization.locations.build @organization.locations_organization.build @organization.user_organization_relationships.build end # GET /organizations/1/edit def edit end # POST /organizations def create @organization = Organization.new(organization_params) params[:organization][:locations_attributes].each do |k, v| @organization.locations << Location.new(locations_organization_params(k)) end @organization.user_organization_relationship << UserOrganizationRelationship.new(:user_id => current_user.id, :relationship => UserOrganizationRelationship::Administrator) if @organization.save! redirect_to @organization, notice: 'Organization was successfully created.' else render action: 'new' end end # PATCH/PUT /organizations/1 def update if @organization.update_attributes(organization_params) redirect_to @organization, notice: 'Organization was successfully updated.' else render action: 'edit' end end # DELETE /organizations/1 def destroy @organization.destroy redirect_to organizations_url, notice: 'Organization was successfully destroyed.' end def members set_organization @organization.user_organization_relationships.build end def nonmembers set_organization #puts "\n\tPARAMS: " + params[:addedUsers].to_json.to_s + "\n" @available_users = User.where(["id NOT IN (?)", @organization.users.map(&:id) + (params[:added] || [])]) html = '