Class: Hicube::SnippetsController

Inherits:
BaseController show all
Defined in:
app/controllers/hicube/snippets_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
# File 'app/controllers/hicube/snippets_controller.rb', line 22

def create
  logger.debug "Creating snippet with #{params}"
  @snippet = Hicube::Snippet.new snippet_params
  @snippet.save!

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

#destroyObject



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

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

#editObject



44
45
# File 'app/controllers/hicube/snippets_controller.rb', line 44

def edit
end

#indexObject



64
65
# File 'app/controllers/hicube/snippets_controller.rb', line 64

def index
end

#newObject



67
68
# File 'app/controllers/hicube/snippets_controller.rb', line 67

def new
end

#updateObject



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

def update
  logger.debug "Updating snippets with #{params}"
  @snippet.update_attributes snippet_params

  @snippet.save!
    
  respond_to do |format|
    notify :notice, ::I18n.t('messages.resource.updated',
      :type       => Hicube::Snippet.model_name.human,
      :resource   => @snippet
    )
    format.html { redirect_to action: :edit }
  end
rescue Mongoid::Errors::Validations => e
  respond_to do |format|
    notify_now :error, ::I18n.t('messages.resource.not_valid',
      :type     => Hicube::Snippet.model_name.human,
      :errors   => @snippet.errors.full_messages.to_sentence
    )
    format.html { render :action => :edit }
  end
end