Class: CamaleonCms::Admin::Appearances::Widgets::MainController

Inherits:
CamaleonCms::AdminController show all
Defined in:
app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb

Instance Method Summary collapse

Methods inherited from CamaleonCms::AdminController

#ajax, #cama_get_i18n_frontend, #dashboard, #search

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb', line 24

def create
  @widget = current_site
            .widgets.new(params.require(:widget_main).permit(:name, :slug, :description, :excerpt, :renderer))
  @widget.status = 'simple'
  if @widget.save!
    flash[:notice] = t('camaleon_cms.admin.widgets.message.created')
  else
    flash[:error] = t('camaleon_cms.admin.widgets.message.error_created')
  end
  redirect_to action: :index
end

#destroyObject



45
46
47
48
49
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb', line 45

def destroy
  @widget = @widget.destroy!
  flash[:notice] = t('camaleon_cms.admin.widgets.message.deleted')
  redirect_to action: :index
end

#editObject



20
21
22
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb', line 20

def edit
  new
end

#indexObject



11
12
13
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb', line 11

def index
  @widgets = current_site.widgets.order :name
end

#newObject



15
16
17
18
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb', line 15

def new
  @widget ||= current_site.widgets.new
  render 'form', layout: false
end

#updateObject



36
37
38
39
40
41
42
43
# File 'app/controllers/camaleon_cms/admin/appearances/widgets/main_controller.rb', line 36

def update
  if @widget.update!(params.require(:widget_main).permit(:name, :slug, :description, :excerpt, :renderer))
    flash[:notice] = t('camaleon_cms.admin.widgets.message.updated')
  else
    flash[:error] = t('camaleon_cms.admin.widgets.message.error_updated')
  end
  redirect_to action: :index
end