Sha256: 182942ce5c3dd42026cb6691cbd924738ed7f076556e72eec95127c22be10695

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

require_dependency "writefully/application_controller"

module Writefully
  class SitesController < ApplicationController
    before_filter :authenticate_wf_authorship!

    VALID_TABS = %w(processing errors)

    def index
      @sites = current_wf_authorship.owned_sites
      redirect_to new_site_path if @sites.empty?
    end

    def show
      @site = get_site
      if params[:tab].nil? or not tab_valid?
        redirect_to site_posts_path(@site) 
      end
    end

    def new
      @site = current_wf_authorship.owned_sites.build
    end

    def edit
      @site = get_site
    end

    def create
      @site = current_wf_authorship.owned_sites.build(site_params)
      if @site.save
        set_flash :success, object: @site
        redirect_to sites_path
      end
    end

  protected

    def tab_valid?
      VALID_TABS.include?(params[:tab])
    end

    def get_site
      current_wf_authorship.owned_sites.friendly.find(params[:id])
    end

    def site_params
      params.require(:site).permit(:name, :domain)
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
writefully-0.4.5 app/controllers/writefully/sites_controller.rb
writefully-0.4.4 app/controllers/writefully/sites_controller.rb
writefully-0.4.2 app/controllers/writefully/sites_controller.rb
writefully-0.4.1 app/controllers/writefully/sites_controller.rb
writefully-0.4.0 app/controllers/writefully/sites_controller.rb
writefully-0.3.6 app/controllers/writefully/sites_controller.rb