socialforge/app/controllers/sub_domains_controller.rb

43 lines
1.4 KiB
Ruby

class SubDomainsController < ApplicationController
layout 'base_org'
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index]
def new
@subdomain = SubDomain.new
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
@organization = @org_subfield.organization
end
def create
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
@res = true
@subfield = OrgSubfield.find(params[:org_subfield_id])
@organization = @subfield.organization
@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)
@subdomain.update_column(:field_type, params[:field_type])
else
@res = false
end
end
def show
render_404
# @subfield_content = @organization.org_subfields.order("priority")
# render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
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