Skip to content

Instantly share code, notes, and snippets.

@breim
Created April 20, 2014 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breim/11126904 to your computer and use it in GitHub Desktop.
Save breim/11126904 to your computer and use it in GitHub Desktop.
*Instalando o devise
*Colocando custom fields para o devise
*Gerando custom views
*Editar quantidade minima para tamanho da senha
*Não permitindo usuário acessar o controller se não estiver logado
*Depois de se cadastrar não logar automaticamente
# Application.html.erb
<% if current_user.present? %>
<%= current_user.email %>
<%= link_to('Sair', destroy_user_session_path, :method => :delete) %>
<% else %>
<%= link_to "Cadastrar", new_user_registration_path %>/
<%= link_to "Entrar", new_user_session_path %>
<% end %>
#
# Application_controller.rb
before_filter :update_sanitized_params, if: :devise_controller?
def update_sanitized_params
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:nome,:email,:password,:password_confirmation)}
devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:nome)}
end
#
# Registrations_controler.rb
class RegistrationsController < Devise::RegistrationsController
# GET /resource/sign_up
def new
build_resource({})
respond_with self.resource
end
def show
end
# POST /resource
def create
build_resource(sign_up_params)
if resource.save
yield resource if block_given?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
def after_sign_up_path_for(resource)
case resource
when User
then root_path
else
root_path
end
end
end
#
@lucas-ns-hunter
Copy link

olá. muito obrigado pela colaboração, porém recomendo que em um proximo video vc deixe comentarios no bloco de nota da ação exata de cada função de codigo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment