Class: Hicube::AccountsController

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

Constant Summary

Constants inherited from ApplicationController

Hicube::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
# File 'app/controllers/hicube/accounts_controller.rb', line 22

def create
  @account = Hicube::Account.new(accounts_params)
  @account.save!

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

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/hicube/accounts_controller.rb', line 43

def update
  @account.update_attributes(accounts_params)
  @account.save!

  notify :notice, ::I18n.t('messages.resource.updated',
    :type       => Hicube::Account.model_name.human,
    :resource   => @account
  )
  render action: :show, id: @account
rescue Mongoid::Errors::Validations => e
  notify_now :error, ::I18n.t('messages.resource.not_valid',
    :type     => Hicube::Account.model_name.human,
    :errors   => @account.errors.full_messages.to_sentence
  )
  render :action => :edit
end