Class: Iugu::AccountDomainsController

Inherits:
AccountSettingsController
  • Object
show all
Defined in:
app/controllers/iugu/account_domains_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
# File 'app/controllers/iugu/account_domains_controller.rb', line 17

def create
  @account = current_user.accounts.find(params[:account_id])
  if @account. << @account_domain = AccountDomain.create(params[:account_domain])
    redirect_to (:account_id => params[:account_id], :domain_id => @account_domain.id)#, :notice => notice = I18n.t("iugu.notices.domain_created")
  else
    @account_domains = @account..where(:account_id => params[:account_id])
    render :index
  end
end

#destroyObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/iugu/account_domains_controller.rb', line 27

def destroy
  flash[:group] = :account_domain
  begin
    @account = current_user.accounts.find(params[:account_id])
    @domain = @account..find(params[:domain_id])
    @domain.destroy
    notice = I18n.t("iugu.notices.domain_destroyed")
  rescue
    notice = I18n.t("iugu.notices.domain_not_found")
  end
  redirect_to (params[:account_id]), :notice => notice
end

#indexObject



7
8
9
10
11
12
13
14
15
# File 'app/controllers/iugu/account_domains_controller.rb', line 7

def index
  unless IuguSDK::enable_custom_domain == false && IuguSDK:: == false
    @account = current_user.accounts.find(params[:account_id])
    @account_domains = @account..where(:account_id => params[:account_id])
    @account_domain = AccountDomain.new
  else
    raise ActionController::RoutingError.new("Not found")
  end
end

#instructionsObject



40
41
42
43
44
45
46
47
# File 'app/controllers/iugu/account_domains_controller.rb', line 40

def instructions
  begin
    @account = current_user.accounts.find(params[:account_id])
    @domain = @account..find(params[:domain_id])
  rescue
    redirect_to (params[:account_id]), :notice => I18n.t("iugu.notices.domain_not_found")
  end
end

#primaryObject



63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/iugu/account_domains_controller.rb', line 63

def primary
  begin
    @account = current_user.accounts.find(params[:account_id])
    @domain = @account..find(params[:domain_id])
    @domain.set_primary
    redirect_to (params[:account_id]), :notice => I18n.t("iugu.notices.domain_set_primary")
  rescue
    redirect_to (params[:account_id]), :notice => I18n.t("iugu.notices.domain_not_found")
  end
end

#update_subdomainObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/iugu/account_domains_controller.rb', line 74

def update_subdomain
  if IuguSDK:: == true
    @account = current_user.accounts.find(params[:account_id])
    if @account.update_attributes(params[:account])
      redirect_to (@account.id), :notice => I18n.t("iugu.notices.subdomain_updated")
    else
      @account_domains = @account..where(:account_id => params[:account_id])
      @account_domain = AccountDomain.new
      render :index
    end
  else
    raise ActionController::RoutingError.new('Not found')
  end
end

#verifyObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/iugu/account_domains_controller.rb', line 49

def verify
  begin
    @account = current_user.accounts.find(params[:account_id])
    @domain = @account..find(params[:domain_id])
    if @domain.verify 
      redirect_to (params[:account_id]), :notice => I18n.t("iugu.notices.domain_verified")
    else
      redirect_to (:account_id => params[:account_id], :domain_id => params[:domain_id]), flash: { :error => I18n.t("iugu.notices.domain_not_verified") }
    end
  rescue
    redirect_to (params[:account_id]), flash: { :error => I18n.t("iugu.notices.domain_not_found") }
  end
end