Skip to content

Instantly share code, notes, and snippets.

@universal
Last active August 29, 2015 14:22
Show Gist options
  • Save universal/7bc154cd0f9ccbda177b to your computer and use it in GitHub Desktop.
Save universal/7bc154cd0f9ccbda177b to your computer and use it in GitHub Desktop.
%div{class: "col-sm-12 affiliation-addresses"}
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :category, :class => "control-label"
=f.select(:category, [['Mail', 'mail'], ['Business', 'business']], {}, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :category)
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :cep, :class => "control-label"
=f.text_field(:cep, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :cep)
%row
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :address, :class => "control-label"
=f.text_field(:address, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :address)
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :number, :class => "control-label"
=f.text_field(:number, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :number)
%row
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :complement, :class => "control-label"
=f.text_field(:complement, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :complement)
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :neighborhood, :class => "control-label"
=f.text_field(:neighborhood, :class => "form-control")
.small-field-error=field_validation_message(affiliation_address, :neighborhood)
%row
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :city, :class => "control-label"
=f.text_field(:city, :class => "form-control")
.small-field-error=field_validation_message(@affiliation_address, :city)
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :state, :class => "control-label"
=f.text_field(:state, :class => "form-control")
.small-field-error=field_validation_message(@affiliation_address, :state)
%row
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :phone, :class => "control-label"
=f.text_field(:phone, :class => "form-control")
.small-field-error=field_validation_message(@affiliation_address, :phone)
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :fax, :class => "control-label"
=f.text_field(:fax, :class => "form-control")
.small-field-error=field_validation_message(@affiliation_address, :fax)
%row
.col-xs-6.col-sm-6.col-md-6
%div{:class => "form-group"}
=f.label :mobile, :class => "control-label"
=f.text_field(:mobile, :class => "form-control")
.small-field-error=field_validation_message(@affiliation_address, :mobile)
.col-xs-6.col-sm-6.col-md-6
=f.hidden_field(:id)
=f.hidden_field :_destroy
=link_to(fa_icon('trash-o', :style => 'margin:0'), "javascript:void(0);", :onclick => "remove_affiliation_form(this, 'affiliation-addresses')", :class => "btn btn-danger btn-sm", :style => 'margin-top: 25px;')
%div{class: "col-sm-3"}
%h3 Endereços
%span Cadastre os endereços disponíveis.
%div{class: "col-sm-3"}
%div{class: "col-sm-9 affiliation_addresses_list"}
=f.fields_for :affiliation_addresses, @merchant.affiliation_addresses do |builder|
=render partial: "merchants/address", locals: {f: builder, affiliation_address: builder.object}
class MerchantRegistrationsController < Devise::RegistrationsController
prepend_before_filter :require_no_authentication, only: [:new, :create, :cancel]
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]
layout 'merchant'
# GET /resource/sign_up
def new
build_resource({})
resource.affiliation_addresses.build
resource.affiliation_owners.build
resource.affiliation_bank_addresses.build
respond_with resource
end
# POST /resource
def create
build_resource(sign_up_params)
unless verify_recaptcha
clean_up_passwords(resource)
flash.delete :recaptcha_error
flash.now[:error] = I18n.t('devise.failure.invalid_captcha')
return render :new
else
flash.delete :recaptcha_error
end
resource.save
yield resource if block_given?
if resource.persisted?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
clean_up_passwords resource
respond_with resource
end
end
# GET /resource/edit
def edit
render :edit
end
# PUT /resource
# We need to use a copy of the resource because we don't want to change
# the current user in place.
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
resource_updated = update_resource(resource, account_update_params)
yield resource if block_given?
if resource_updated
if is_flashing_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
else
clean_up_passwords resource
respond_with resource
end
end
# DELETE /resource
def destroy
resource.destroy
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_flashing_format?
yield resource if block_given?
respond_with_navigational(resource) { redirect_to after_sign_out_path_for(resource_name) }
end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
def cancel
expire_data_after_sign_in!
redirect_to new_registration_path(resource_name)
end
protected
def update_needs_confirmation?(resource, previous)
resource.respond_to?(:pending_reconfirmation?) &&
resource.pending_reconfirmation? &&
previous != resource.unconfirmed_email
end
# Check whether it's necessary to use the password
def update_resource(resource, params)
resource.update_without_password(params)
end
# Build a devise resource passing in the session. Useful to move
# temporary session data to the newly created user.
def build_resource(hash = nil)
self.resource = resource_class.new_with_session(hash || {}, session)
end
# Signs in a user on sign up. You can overwrite this method in your own
# RegistrationsController.
def sign_up(resource_name, resource)
sign_in(resource_name, resource)
end
# The path used after sign up. You need to overwrite this method
# in your own RegistrationsController.
def after_sign_up_path_for(resource)
merchant_path(resource)
end
# The path used after sign up for inactive accounts. You need to overwrite
# this method in your own RegistrationsController.
def after_inactive_sign_up_path_for(_resource)
respond_to?(:root_path) ? root_path : '/'
end
# The default url to be used after updating a resource. You need to overwrite
# this method in your own RegistrationsController.
def after_update_path_for(resource)
merchant_path(resource)
end
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!", force: true)
self.resource = send(:"current_#{resource_name}")
end
def sign_up_params
devise_parameter_sanitizer.sanitize(:sign_up)
end
def account_update_params
devise_parameter_sanitizer.sanitize(:account_update)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment