class SubDomainsController < ApplicationController layout 'base_org' before_filter :find_org_subfield_and_subdomain, :only => [:show, :index] def create if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0 @res = true # @organization = Organization.find(params[:organization_id]) @subfield = OrgSubfield.find(params[:org_subfield_id]) # @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1) @subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id],:priority => @subfield.sub_domains.blank? ? 1.1 : @subfield.sub_domains.order("priority").last.priority + 0.1) # if !params[:sub_dir].blank? # sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ # "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" # if SubfieldSubdomainDir.find_by_sql(sql).count == 0 # SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase) # end # end @subdomain.update_column(:field_type, params[:field_type]) else @res = false end end def show @subfield_content = @organization.org_subfields.order("priority") render layout: 'base_sub_domain' end def index end private def find_org_subfield_and_subdomain @subfield = OrgSubfield.find(params[:org_subfield_id]) @subdomain = SubDomain.find(params[:id]) @organization = @subfield.organization rescue ActiveRecord::RecordNotFound # source_subdomain not found render_404 end end