app/controllers/iugu/account_controller.rb in iugusdk-1.0.0.alpha.3 vs app/controllers/iugu/account_controller.rb in iugusdk-1.0.0.alpha.4
- old
+ new
@@ -16,13 +16,17 @@
@primary_domain = @account.account_domains.where(:primary => true).first if @account
render 'iugu/settings/account'
end
def destroy
- account = current_user.accounts.find(params[:id])
- account.destroy
- redirect_to(account_settings_path, :notice => I18n.t("iugu.account_destruction_in") + account.destruction_job.run_at.to_s)
+ if IuguSDK::enable_account_cancel
+ account = current_user.accounts.find(params[:id])
+ account.destroy
+ redirect_to(account_settings_path, :notice => I18n.t("iugu.account_destruction_in") + account.destruction_job.run_at.to_s)
+ else
+ raise ActionController::RoutingError.new('Not found')
+ end
end
def cancel_destruction
current_user.accounts.find(params[:id]).cancel_destruction
notice = I18n.t("iugu.account_destruction_undone")
@@ -47,12 +51,17 @@
end
def generate_new_token
if IuguSDK::enable_account_api
@account = current_user.accounts.find(params[:account_id])
- @account.update_api_token
+ token = @account.tokens.create(description: params[:description], api_type: params[:api_type])
+ if token.new_record?
+ notice = token.errors.full_messages
+ else
+ notice = I18n.t("iugu.notices.new_token_generated")
+ end
flash[:group] = :api_token
- redirect_to account_view_path(params[:account_id]), :notice => I18n.t("iugu.notices.new_token_generated")
+ redirect_to account_view_path(params[:account_id]), :notice => notice
else
raise ActionController::RoutingError.new('Not found')
end
end