socialforge/app/controllers/sub_domains_controller.rb

51 lines
2.1 KiB
Ruby
Raw Normal View History

2016-05-04 09:01:51 +08:00
class SubDomainsController < ApplicationController
layout 'base_org'
2016-05-04 15:05:54 +08:00
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index]
2016-05-04 09:01:51 +08:00
def new
@subdomain = SubDomain.new
2016-05-04 15:05:54 +08:00
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
2016-05-04 15:50:53 +08:00
@organization = @org_subfield.organization
2016-05-04 09:01:51 +08:00
end
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
2016-05-04 11:08:16 +08:00
render_404
# @subfield_content = @organization.org_subfields.order("priority")
# render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
2016-05-04 09:01:51 +08:00
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