Class: Hicube::PagesController

Inherits:
BaseController show all
Defined in:
app/controllers/hicube/pages_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::FLASH_TYPES

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #notify, #notify_now

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/hicube/pages_controller.rb', line 22

def create
  logger.debug "Creating page with #{params}"
  @page = Hicube::Page.new page_params
  @page.seo_title = "#{app_name} - #{@page.title}" if (@page.seo_title.nil? or @page.seo_title.empty?)
  @page.save!

  
  respond_to do |format|
    notify :notice, ::I18n.t('messages.resource.created',
      :type       => Hicube::Page.model_name.human,
      :resource   => @page
    )
    format.html { redirect_to action: :edit, id: @page }
  end
rescue Mongoid::Errors::Validations => e
  respond_to do |format|
    notify_now :error, ::I18n.t('messages.resource.not_valid',
      :type     => Hicube::Page.model_name.human,
      :errors   => @page.errors.full_messages.to_sentence
    )
    format.html { render :action => :new, :status => 422 }
  end
end

#destroyObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/hicube/pages_controller.rb', line 46

def destroy
  @page.destroy
  respond_to do |format|
    notify :notice, ::I18n.t('messages.resource.destroyed',
      :type       => Hicube::Page.model_name.human,
      :resource   => @page
    )
    format.html { redirect_to action: :index }
  end
rescue
  respond_to do |format|
    notify :error, ::I18n.t('messages.resource.not_valid',
      :type     => Hicube::Page.model_name.human,
      :errors   => @page.errors.full_messages.to_sentence
    )
    format.html { redirect_to action: :edit, id: @page }
  end
end

#editObject



65
66
# File 'app/controllers/hicube/pages_controller.rb', line 65

def edit
end

#newObject



68
69
# File 'app/controllers/hicube/pages_controller.rb', line 68

def new
end

#updateObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/hicube/pages_controller.rb', line 71

def update
  logger.debug "Updating Pages with #{params}"
  @page.update_attributes page_params
  @page.seo_title = "#{app_name} - #{@page.title}" if (@page.seo_title.nil? or @page.seo_title.empty?)
  
  @page.save!
    
  respond_to do |format|
    notify :notice, ::I18n.t('messages.resource.updated',
      :type       => Hicube::Page.model_name.human,
      :resource   => @page
    )
    format.html { redirect_to action: :edit, id: @page }
  end
rescue Mongoid::Errors::Validations => e
  respond_to do |format|
    notify_now :error, ::I18n.t('messages.resource.not_valid',
      :type     => Hicube::Page.model_name.human,
      :errors   => @page.errors.full_messages.to_sentence
    )
    format.html { render :action => :edit, id: @page, :status => 422 }
  end
end