Class: Kryptonite::ContentsController

Inherits:
KryptoniteController show all
Defined in:
lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb

Instance Method Summary collapse

Methods inherited from KryptoniteController

#blank

Methods included from ConfigHelper

#kryptonite_config_dashboard_url, #kryptonite_config_email_from_address, #kryptonite_config_hostname, #kryptonite_config_javascript_includes, #kryptonite_config_logo, #kryptonite_config_stylesheet_includes, #kryptonite_config_website_name

Methods included from KryptoniteHelper

#kryptonite_assets_field, #kryptonite_check_box, #kryptonite_check_box_group, #kryptonite_collection_select, #kryptonite_date_select, #kryptonite_datetime_select, #kryptonite_file_field, #kryptonite_generate_page_title, #kryptonite_get_access_level_array, #kryptonite_get_access_level_text, #kryptonite_get_full_version_string, #kryptonite_get_language_array, #kryptonite_get_short_version_string, #kryptonite_get_version_info, #kryptonite_hidden_field, #kryptonite_password_field, #kryptonite_radio_button, #kryptonite_radio_button_group, #kryptonite_select, #kryptonite_show_icon, #kryptonite_show_row_icon, #kryptonite_table_cell_link, #kryptonite_table_cell_no_link, #kryptonite_text_area, #kryptonite_text_area_big, #kryptonite_text_field, #kryptonite_time_select, #kryptonite_time_zone_select

Instance Method Details

#add_assetObject

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]



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 8

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

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 49

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

#destroyObject



91
92
93
94
95
96
97
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 91

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

#indexObject



34
35
36
37
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 34

def index
  @kryptonite_page_title = t("kryptonite.contents.plural_name_cap")
@contents = Content.paginate :page => params[:page]
end

#newObject



44
45
46
47
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 44

def new
  @kryptonite_page_title = t("scaffold_add_new", :model=>t("kryptonite.contents.singular_name_down"))
	@content = Content.new
end

#saveallObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 23

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

#showObject



39
40
41
42
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 39

def show
  @kryptonite_page_title = t("scaffold_view", :model=>t("kryptonite.contents.singular_name_down"))
  @content = Content.find params[:id]
end

#updateObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/generators/kryptonite/basics/templates/app/controller/kryptonite/contents_controller.rb', line 69

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