module Kryptonite class ContentsController < Kryptonite::KryptoniteController ## optional filters for defining usage according to Kryptonite::Users access_levels # before_filter :needs_admin, :except => [:action1, :action2] # before_filter :needs_admin_or_current_user, :only => [:action1, :action2] def add_asset @content = Content.find_or_create_by_content_key(:content_key=>params[:id], :body=>config[:default]) if params[:ffmultiple] == "true" @asset = Asset.new() else @asset = Asset.find_or_create_by_content_id(@content.id) end @asset.content_id = @content.id @asset.size = params[:ffsize] @asset.file = @file @asset.save @asset.reload render :text => '{"success": true, "file": "'+@asset.file.url(:normal)+'"}' end def saveall params[:content].each do |key, value| content = Content.find key.split('_')[1] content.body = value[:value] content.save end respond_to do |format| format.json { render :text=>"" } end end def index @kryptonite_page_title = t("kryptonite.contents.plural_name_cap") @contents = Content.paginate :page => params[:page] end def show @kryptonite_page_title = t("scaffold_view", :model=>t("kryptonite.contents.singular_name_down")) @content = Content.find params[:id] end def new @kryptonite_page_title = t("scaffold_add_new", :model=>t("kryptonite.contents.singular_name_down")) @content = Content.new end def create @content = Content.new params[:content] respond_to do |format| if @content.save format.html { flash[:notice] = t("scaffold_created", :model=>t("kryptonite.contents.singular_name_cap")) redirect_to kryptonite_contents_path } format.json { respond_with_bip(@content) } else format.html { flash.now[:warning] = t("scaffold_problems_creating", :model=>t("kryptonite.contents.singular_name_down")) render :action => :new } format.json { respond_with_bip(@content) } end end end def update @kryptonite_page_title = t("scaffold_update", :model=>t("kryptonite.contents.singular_name_down")) @content = Content.find params[:id] respond_to do |format| if @content.update_attributes params[:content] format.html { flash[:notice] = t("scaffold_updated", :model=>t("kryptonite.contents.singular_name_cap")) redirect_to kryptonite_contents_path } format.json { respond_with_bip(@content) } else format.html { flash.now[:warning] = t("scaffold_problems_updating", :model=>t("kryptonite.contents.singular_name_down")) render :action => :show } format.json { respond_with_bip(@content) } end end end def destroy @content = Content.find params[:id] @content.destroy flash[:notice] = t("scaffold_deleted", :model=>t("kryptonite.contents.singular_name_cap")) redirect_to kryptonite_contents_path end end end