Sha256: 0396cb24c15329f7c999b2fcd8b4326ab97b75fb572db7d0f12be31bc944a9c1
Contents?: true
Size: 1.89 KB
Versions: 5
Compression:
Stored size: 1.89 KB
Contents
class Admin::InstallController < ApplicationController helper :base before_action :normalize_install_params, :only => :index before_action :protect_install, :except => :confirmation layout "simple" renders_with_error_proc :below_field def index # TODO: can't we somehow encapsulate all this in a single model instead of juggling with 3 different models? params[:section] = params[:section] params[:section] ||= { :title => t(:'adva.sites.install.section_default') } params[:section][:type] ||= 'Page' @site = Site.new(params[:site]) @section = @site.sections.build(params[:section]) @user = User.new(params[:user]) @user.name = @user.first_name_from_email @user.verified_at = Time.zone.now @article = @section.articles.build({ title: t(:'adva.sites.install.section_default'), body: t(:'adva.sites.install.section_default'), author: @user, published_at: Time.zone.now, }) if request.post? if @site.valid? && @section.valid? && @article.valid? && @user.valid? @site.save @user.admin = true authenticate_user(:email => @user.email, :password => @user.password) # default email for site @site.email ||= @user.email @site.save flash.now[:notice] = t(:'adva.sites.flash.install.success') render :action => :confirmation else models = [@site, @section, @article, @user].map { |model| model.class.name unless model.valid? }.compact flash.now[:error] = t(:'adva.sites.flash.install.failure', :models => models.join(', ')) end end end protected def normalize_install_params params[:site] ||= {} params[:site].merge!(:host => request.host_with_port) end def protect_install if Site.first || User.first flash[:error] = t(:'adva.sites.flash.install.error_already_complete') redirect_to admin_sites_url end end end
Version data entries
5 entries across 5 versions & 1 rubygems