socialforge/app/controllers/sub_domains_controller.rb

43 lines
1.4 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
@subfield = OrgSubfield.find(params[:org_subfield_id])
2016-05-04 17:06:32 +08:00
@organization = @subfield.organization
2016-05-04 09:01:51 +08:00
@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
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