Sha256: efd41a277dcfe668535622b5da92eda88b9b5da5786d5fd35853a697d8865ff8
Contents?: true
Size: 1.97 KB
Versions: 4
Compression:
Stored size: 1.97 KB
Contents
require_dependency "pages_cms/application_controller" module PagesCms class Admin::AccountsController < ApplicationController before_action :logged_in_admin def new @account = Account.new end def index @accounts = Account.all end def create @account = Account.new(account_params) if @account.save @account.pages.create!(title: 'Home') Rails.application.reload_routes! session[:current_account] = @account.id flash[:success] = 'Account created' redirect_to admin_accounts_path else flash[:danger] = "Failed to create: #{@account.errors.full_messages.to_sentence}" redirect_to admin_accounts_path end end def edit @account = Account.find(params[:id]) end def update @account = Account.find(params[:id]) if @account.update(account_params) flash[:success] = 'Account updated' redirect_to admin_accounts_path else flash[:danger] = "Failed to update: #{@account.errors.full_messages.to_sentence}" redirect_to admin_accounts_path end end def site if Account.exists?(params[:account]) session[:current_account] = params[:account] current_account = PagesCms::Account.find(params[:account]) flash[:success] = "Site changed to #{current_account.site_name}" redirect_to admin_accounts_path else flash[:danger] = 'Site does not exist!' redirect_to admin_accounts_path end end def destroy account = Account.find(params[:id]) if session[:current_account] == account.id session[:current_account] = nil end account.destroy flash[:success] = 'Account destroyed' redirect_to admin_accounts_path end private def account_params params.require(:account).permit( :name, :email, :site_name, :mount_location, :web_address, :meta_tags, :meta_description ) end end end
Version data entries
4 entries across 4 versions & 1 rubygems