Sha256: 9366dd89c1ec1054ea6dccf244c8a3851a540bd7fcfb90630045ec1d0e0a8af2

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

class Cms::AssetsController < Cms::MainController
  authenticate_user :all

  def show
    @asset = @context.assets.find params[:id]
  end

  def new
    @asset = create_tagged_asset
  end

  def create
    @asset = @context.assets.build
    @asset.assign_ordered_attributes params[:cms_asset]

    if @asset.save
      flash[:notice] = t('assets.flash.created')
      redirect_to cms_root_path
    else
      render :action => 'new'
    end
  end

  def edit
    @asset = @context.assets.find params[:id]
  end

  def update
    @asset = @context.assets.find params[:id]
    @asset.assign_ordered_attributes params[:cms_asset]

    if @asset.save
      flash[:notice] = t('assets.flash.updated')
      redirect_to cms_root_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @asset = @context.assets.find(params[:id])
    @asset.destroy

    flash[:notice] = t('assets.flash.deleted')
    
    respond_to do |format|
      format.html { redirect_to cms_root_path }
    end
  end

protected
  # pre-populate an asset with tagged data and meta fields if a tag param is present
  def create_tagged_asset
    asset = Cms::Asset.new
    curr_tag = (params[:tag] || '').strip

    if curr_tag.present?
      asset.tag_list = curr_tag
    
      meta_asset = @context.assets.tagged_with(curr_tag).first :conditions => 'meta_data is not null'
      if meta_asset
        # remove meta values since we only want the key names
        # new values will be provided for the new asset
        asset.meta_data = meta_asset.meta_data.collect{|m| {:name => m[:name], :value => ''}}

        # assign custom dims
        asset.custom_width = meta_asset.custom_width
        asset.custom_height = meta_asset.custom_height
      end

      asset
    else
      asset
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
liquid_cms-0.2.1.1 app/controllers/cms/assets_controller.rb
liquid_cms-0.3.1.0 app/controllers/cms/assets_controller.rb
liquid_cms-0.2.1.0 app/controllers/cms/assets_controller.rb