Created
February 19, 2014 05:15
-
-
Save julioprotzek/9086421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Paporeto::Application.configure do | |
# Settings specified here will take precedence over those in config/application.rb. | |
# In the development environment your application's code is reloaded on | |
# every request. This slows down response time but is perfect for development | |
# since you don't have to restart the web server when you make code changes. | |
config.cache_classes = false | |
# Do not eager load code on boot. | |
config.eager_load = false | |
# Show full error reports and disable caching. | |
config.consider_all_requests_local = true | |
config.action_controller.perform_caching = false | |
# Don't care if the mailer can't send. | |
config.action_mailer.raise_delivery_errors = false | |
# Print deprecation notices to the Rails logger. | |
config.active_support.deprecation = :log | |
# Raise an error on page load if there are pending migrations | |
config.active_record.migration_error = :page_load | |
# Debug mode disables concatenation and preprocessing of assets. | |
# This option may cause significant delays in view rendering with a large | |
# number of complex assets. | |
config.assets.debug = true | |
config.action_controller.action_on_unpermitted_parameters = :raise | |
config.action_mailer.default_url_options = { :host => 'localhost:3000' } | |
config.action_mailer.delivery_method = :smtp | |
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this hook to configure devise mailer, warden hooks and so forth. | |
# Many of these configuration options can be set straight in your model. | |
Devise.setup do |config| | |
# The secret key used by Devise. Devise uses this key to generate | |
# random tokens. Changing this key will render invalid all existing | |
# confirmation, reset password and unlock tokens in the database. | |
config.secret_key = '63f85a07842ffe600734bf8f44c535a23eda901c6ede1616afc13d1bab7119312f6dde53cdcfe9e0f9fae048378b0bcac961f4a1530f53171a74de87ae6e4ec1' | |
# ==> Mailer Configuration | |
# Configure the e-mail address which will be shown in Devise::Mailer, | |
# note that it will be overwritten if you use your own mailer class | |
# with default "from" parameter. | |
config.mailer_sender = 'equipe@paporeto.com.br' | |
# Configure the class responsible to send e-mails. | |
# config.mailer = 'Devise::Mailer' | |
# ==> ORM configuration | |
# Load and configure the ORM. Supports :active_record (default) and | |
# :mongoid (bson_ext recommended) by default. Other ORMs may be | |
# available as additional gems. | |
require 'devise/orm/active_record' | |
# ==> Configuration for any authentication mechanism | |
# Configure which keys are used when authenticating a user. The default is | |
# just :email. You can configure it to use [:username, :subdomain], so for | |
# authenticating a user, both parameters are required. Remember that those | |
# parameters are used only when authenticating and not when retrieving from | |
# session. If you need permissions, you should implement that in a before filter. | |
# You can also supply a hash where the value is a boolean determining whether | |
# or not authentication should be aborted when the value is not present. | |
# config.authentication_keys = [ :email ] | |
# Configure parameters from the request object used for authentication. Each entry | |
# given should be a request method and it will automatically be passed to the | |
# find_for_authentication method and considered in your model lookup. For instance, | |
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication. | |
# The same considerations mentioned for authentication_keys also apply to request_keys. | |
# config.request_keys = [] | |
# Configure which authentication keys should be case-insensitive. | |
# These keys will be downcased upon creating or modifying a user and when used | |
# to authenticate or find a user. Default is :email. | |
config.case_insensitive_keys = [ :email ] | |
# Configure which authentication keys should have whitespace stripped. | |
# These keys will have whitespace before and after removed upon creating or | |
# modifying a user and when used to authenticate or find a user. Default is :email. | |
config.strip_whitespace_keys = [ :email ] | |
# Tell if authentication through request.params is enabled. True by default. | |
# It can be set to an array that will enable params authentication only for the | |
# given strategies, for example, `config.params_authenticatable = [:database]` will | |
# enable it only for database (email + password) authentication. | |
# config.params_authenticatable = true | |
# Tell if authentication through HTTP Auth is enabled. False by default. | |
# It can be set to an array that will enable http authentication only for the | |
# given strategies, for example, `config.http_authenticatable = [:database]` will | |
# enable it only for database authentication. The supported strategies are: | |
# :database = Support basic authentication with authentication key + password | |
# config.http_authenticatable = false | |
# If http headers should be returned for AJAX requests. True by default. | |
# config.http_authenticatable_on_xhr = true | |
# The realm used in Http Basic Authentication. 'Application' by default. | |
# config.http_authentication_realm = 'Application' | |
# It will change confirmation, password recovery and other workflows | |
# to behave the same regardless if the e-mail provided was right or wrong. | |
# Does not affect registerable. | |
# config.paranoid = true | |
# By default Devise will store the user in session. You can skip storage for | |
# particular strategies by setting this option. | |
# Notice that if you are skipping storage for all authentication paths, you | |
# may want to disable generating routes to Devise's sessions controller by | |
# passing :skip => :sessions to `devise_for` in your config/routes.rb | |
config.skip_session_storage = [:http_auth] | |
# By default, Devise cleans up the CSRF token on authentication to | |
# avoid CSRF token fixation attacks. This means that, when using AJAX | |
# requests for sign in and sign up, you need to get a new CSRF token | |
# from the server. You can disable this option at your own risk. | |
# config.clean_up_csrf_token_on_authentication = true | |
# ==> Configuration for :database_authenticatable | |
# For bcrypt, this is the cost for hashing the password and defaults to 10. If | |
# using other encryptors, it sets how many times you want the password re-encrypted. | |
# | |
# Limiting the stretches to just one in testing will increase the performance of | |
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use | |
# a value less than 10 in other environments. | |
config.stretches = Rails.env.test? ? 1 : 10 | |
# Setup a pepper to generate the encrypted password. | |
# config.pepper = '6984955c2d7ac8ce085ca87b52f5c5e1ea7cd2af4c150e476cffab8052bb111cb9644ce6aea199d68cf5d0492d4307d57302e1c604ba75cc74c72a954faaacc0' | |
# ==> Configuration for :confirmable | |
# A period that the user is allowed to access the website even without | |
# confirming his account. For instance, if set to 2.days, the user will be | |
# able to access the website for two days without confirming his account, | |
# access will be blocked just in the third day. Default is 0.days, meaning | |
# the user cannot access the website without confirming his account. | |
# config.allow_unconfirmed_access_for = 2.days | |
# A period that the user is allowed to confirm their account before their | |
# token becomes invalid. For example, if set to 3.days, the user can confirm | |
# their account within 3 days after the mail was sent, but on the fourth day | |
# their account can't be confirmed with the token any more. | |
# Default is nil, meaning there is no restriction on how long a user can take | |
# before confirming their account. | |
# config.confirm_within = 3.days | |
# If true, requires any email changes to be confirmed (exactly the same way as | |
# initial account confirmation) to be applied. Requires additional unconfirmed_email | |
# db field (see migrations). Until confirmed new email is stored in | |
# unconfirmed email column, and copied to email column on successful confirmation. | |
config.reconfirmable = true | |
# Defines which key will be used when confirming an account | |
# config.confirmation_keys = [ :email ] | |
# ==> Configuration for :rememberable | |
# The time the user will be remembered without asking for credentials again. | |
# config.remember_for = 2.weeks | |
# If true, extends the user's remember period when remembered via cookie. | |
# config.extend_remember_period = false | |
# Options to be passed to the created cookie. For instance, you can set | |
# :secure => true in order to force SSL only cookies. | |
# config.rememberable_options = {} | |
# ==> Configuration for :validatable | |
# Range for password length. Default is 8..128. | |
config.password_length = 8..128 | |
# Email regex used to validate email formats. It simply asserts that | |
# one (and only one) @ exists in the given string. This is mainly | |
# to give user feedback and not to assert the e-mail validity. | |
# config.email_regexp = /\A[^@]+@[^@]+\z/ | |
# ==> Configuration for :timeoutable | |
# The time you want to timeout the user session without activity. After this | |
# time the user will be asked for credentials again. Default is 30 minutes. | |
# config.timeout_in = 30.minutes | |
# If true, expires auth token on session timeout. | |
# config.expire_auth_token_on_timeout = false | |
# ==> Configuration for :lockable | |
# Defines which strategy will be used to lock an account. | |
# :failed_attempts = Locks an account after a number of failed attempts to sign in. | |
# :none = No lock strategy. You should handle locking by yourself. | |
# config.lock_strategy = :failed_attempts | |
# Defines which key will be used when locking and unlocking an account | |
# config.unlock_keys = [ :email ] | |
# Defines which strategy will be used to unlock an account. | |
# :email = Sends an unlock link to the user email | |
# :time = Re-enables login after a certain amount of time (see :unlock_in below) | |
# :both = Enables both strategies | |
# :none = No unlock strategy. You should handle unlocking by yourself. | |
# config.unlock_strategy = :both | |
# Number of authentication tries before locking an account if lock_strategy | |
# is failed attempts. | |
# config.maximum_attempts = 20 | |
# Time interval to unlock the account if :time is enabled as unlock_strategy. | |
# config.unlock_in = 1.hour | |
# Warn on the last attempt before the account is locked. | |
# config.last_attempt_warning = false | |
# ==> Configuration for :recoverable | |
# | |
# Defines which key will be used when recovering the password for an account | |
# config.reset_password_keys = [ :email ] | |
# Time interval you can reset your password with a reset password key. | |
# Don't put a too small interval or your users won't have the time to | |
# change their passwords. | |
config.reset_password_within = 6.hours | |
# ==> Configuration for :encryptable | |
# Allow you to use another encryption algorithm besides bcrypt (default). You can use | |
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, | |
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior) | |
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy | |
# REST_AUTH_SITE_KEY to pepper). | |
# | |
# Require the `devise-encryptable` gem when using anything other than bcrypt | |
# config.encryptor = :sha512 | |
# ==> Scopes configuration | |
# Turn scoped views on. Before rendering "sessions/new", it will first check for | |
# "users/sessions/new". It's turned off by default because it's slower if you | |
# are using only default views. | |
# config.scoped_views = false | |
# Configure the default scope given to Warden. By default it's the first | |
# devise role declared in your routes (usually :user). | |
# config.default_scope = :user | |
# Set this configuration to false if you want /users/sign_out to sign out | |
# only the current scope. By default, Devise signs out all scopes. | |
# config.sign_out_all_scopes = true | |
# ==> Navigation configuration | |
# Lists the formats that should be treated as navigational. Formats like | |
# :html, should redirect to the sign in page when the user does not have | |
# access, but formats like :xml or :json, should return 401. | |
# | |
# If you have any extra navigational formats, like :iphone or :mobile, you | |
# should add them to the navigational formats lists. | |
# | |
# The "*/*" below is required to match Internet Explorer requests. | |
# config.navigational_formats = ['*/*', :html] | |
# The default HTTP method used to sign out a resource. Default is :delete. | |
config.sign_out_via = :delete | |
# ==> OmniAuth | |
# Add a new OmniAuth provider. Check the wiki for more information on setting | |
# up on your models and hooks. | |
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' | |
# ==> Warden configuration | |
# If you want to use other strategies, that are not supported by Devise, or | |
# change the failure app, you can configure them inside the config.warden block. | |
# | |
# config.warden do |manager| | |
# manager.intercept_401 = false | |
# manager.default_strategies(:scope => :user).unshift :some_external_strategy | |
# end | |
# ==> Mountable engine configurations | |
# When using Devise inside an engine, let's call it `MyEngine`, and this engine | |
# is mountable, there are some extra configurations to be taken into account. | |
# The following options are available, assuming the engine is mounted as: | |
# | |
# mount MyEngine, at: '/my_engine' | |
# | |
# The router that invoked `devise_for`, in the example above, would be: | |
# config.router_name = :my_engine | |
# | |
# When using omniauth, Devise cannot automatically set Omniauth path, | |
# so you need to do it manually. For the users scope, it would be: | |
# config.omniauth_path_prefix = '/my_engine/users/auth' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.row.vertical-offset-100 | |
.col-md-4.col-md-offset-4 | |
.panel.panel-default | |
.panel-heading | |
h2 Alterar senha | |
.panel-body | |
= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| | |
= f.error_notification | |
= f.input :reset_password_token, :as => :hidden | |
= f.full_error :reset_password_token | |
.form-inputs | |
= f.input :password, :label => "Nova senha", :required => true, :autofocus => true | |
= f.input :password_confirmation, :label => "Confirme sua nova senha", :required => true | |
.form-actions | |
= f.button :submit, "Alterar senha", class: 'btn btn-lg btn-success btn-block' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.row.vertical-offset-100 | |
.col-md-4.col-md-offset-4 | |
.panel.panel-default | |
.panel-heading | |
h2 Esqueceu a senha? | |
.panel-body | |
= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| | |
= f.error_notification | |
.form-inputs | |
= f.input :email, :required => true, :autofocus => true | |
.form-actions | |
= f.button :submit, "Enviar instruções para nova senha", class: 'btn btn-lg btn-success btn-block' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.row.vertical-offset-100 | |
.col-md-4.col-md-offset-4 | |
.panel.panel-default | |
.panel-heading | |
h2 Paporeto | |
.panel-body | |
- if alert | |
.alert.alert-warning.alert-dismissable | |
button type="button" class="close" data-dismiss="alert" aria-hidden="true" × | |
= alert | |
= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {autocomplete: 'off'}) do |f| | |
.form-inputs | |
= f.input :email, :required => false, label: false, placeholder: 'Email', :autofocus => true | |
= f.input :password, :required => false, label: false, placeholder: 'Senha' | |
= f.input :remember_me, :as => :boolean, label: 'Lembrar' if devise_mapping.rememberable? | |
.form-actions | |
= f.button :submit, "Entrar", class: 'btn btn-lg btn-success btn-block' | |
= link_to "Esqueceu a senha?", new_password_path(resource_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style="font-family: sans-serif"> | |
<p>Olá <%= @resource.name %>,</p> | |
<p>Alguém solicitou a mudança da sua senha. Você pode fazer isso através do link abaixo.</p> | |
<p><%= link_to 'Alterar minha senha', edit_password_url(@resource, :reset_password_token => @token) %></p> | |
<p>Se você não fez essa solicitação, por favor ignore esse email.</p> | |
<p>Sua senha não vai mudar até você acessar o link acima e criar uma nova.</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Paporeto::Application.routes.draw do | |
devise_for :users | |
resources :categories, except: :show | |
resources :articles | |
resources :users, except: :show | |
root 'articles#index' | |
# The priority is based upon order of creation: first created -> highest priority. | |
# See how all your routes lay out with "rake routes". | |
# You can have the root of your site routed with "root" | |
# root 'welcome#index' | |
# Example of regular route: | |
# get 'products/:id' => 'catalog#view' | |
# Example of named route that can be invoked with purchase_url(id: product.id) | |
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | |
# Example resource route (maps HTTP verbs to controller actions automatically): | |
# resources :products | |
# Example resource route with options: | |
# resources :products do | |
# member do | |
# get 'short' | |
# post 'toggle' | |
# end | |
# | |
# collection do | |
# get 'sold' | |
# end | |
# end | |
# Example resource route with sub-resources: | |
# resources :products do | |
# resources :comments, :sales | |
# resource :seller | |
# end | |
# Example resource route with more complex sub-resources: | |
# resources :products do | |
# resources :comments | |
# resources :sales do | |
# get 'recent', on: :collection | |
# end | |
# end | |
# Example resource route with concerns: | |
# concern :toggleable do | |
# post 'toggle' | |
# end | |
# resources :posts, concerns: :toggleable | |
# resources :photos, concerns: :toggleable | |
# Example resource route within a namespace: | |
# namespace :admin do | |
# # Directs /admin/products/* to Admin::ProductsController | |
# # (app/controllers/admin/products_controller.rb) | |
# resources :products | |
# end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.destroy_all | |
User.create!(name: 'Julio Protzek', email: 'julio@startae.com.br', password: '123123123') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pt-BR: | |
simple_form: | |
yes: Sim | |
no: Não | |
required: | |
text: obrigatório | |
mark: "*" | |
# You can uncomment the line below if you need to overwrite the whole required html. | |
# When using html, text and mark won't be used. | |
# html: "<abbr title="required">*</abbr>" | |
error_notification: | |
default_message: "Por favor, corrija os problemas abaixo:" | |
# Labels and hints examples | |
labels: | |
defaults: | |
password: Senha | |
password_confirmation: Confirmar a Senha | |
name: Nome | |
article: | |
title: Título | |
body: Texto | |
published_at: Publicado em | |
category: Categoria | |
# hints: | |
# defaults: | |
# password: 'Mínimo de 8 caracteres.' | |
# placeholders: | |
# defaults: | |
# name: 'Nome' | |
# password: '****' | |
helpers: | |
submit: | |
create: 'Criar' | |
update: 'Editar' | |
article: | |
create: 'Criar artigo' | |
update: 'Editar artigo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this setup block to configure all options available in SimpleForm. | |
SimpleForm.setup do |config| | |
# Wrappers are used by the form builder to generate a | |
# complete input. You can remove any component from the | |
# wrapper, change the order or even add your own to the | |
# stack. The options given below are used to wrap the | |
# whole input. | |
config.wrappers :default, class: :input, | |
hint_class: :field_with_hint, error_class: :field_with_errors do |b| | |
## Extensions enabled by default | |
# Any of these extensions can be disabled for a | |
# given input by passing: `f.input EXTENSION_NAME => false`. | |
# You can make any of these extensions optional by | |
# renaming `b.use` to `b.optional`. | |
# Determines whether to use HTML5 (:email, :url, ...) | |
# and required attributes | |
b.use :html5 | |
# Calculates placeholders automatically from I18n | |
# You can also pass a string as f.input placeholder: "Placeholder" | |
b.use :placeholder | |
## Optional extensions | |
# They are disabled unless you pass `f.input EXTENSION_NAME => :lookup` | |
# to the input. If so, they will retrieve the values from the model | |
# if any exists. If you want to enable the lookup for any of those | |
# extensions by default, you can change `b.optional` to `b.use`. | |
# Calculates maxlength from length validations for string inputs | |
b.optional :maxlength | |
# Calculates pattern from format validations for string inputs | |
b.optional :pattern | |
# Calculates min and max from length validations for numeric inputs | |
b.optional :min_max | |
# Calculates readonly automatically from readonly attributes | |
b.optional :readonly | |
## Inputs | |
b.use :label_input | |
b.use :hint, wrap_with: { tag: :span, class: :hint } | |
b.use :error, wrap_with: { tag: :span, class: :error } | |
end | |
# The default wrapper to be used by the FormBuilder. | |
config.default_wrapper = :default | |
# Define the way to render check boxes / radio buttons with labels. | |
# Defaults to :nested for bootstrap config. | |
# inline: input + label | |
# nested: label > input | |
config.boolean_style = :nested | |
# Default class for buttons | |
config.button_class = 'btn' | |
# Method used to tidy up errors. Specify any Rails Array method. | |
# :first lists the first message for each field. | |
# Use :to_sentence to list all errors for each field. | |
# config.error_method = :first | |
# Default tag used for error notification helper. | |
config.error_notification_tag = :div | |
# CSS class to add for error notification helper. | |
config.error_notification_class = 'alert alert-warning' | |
# ID to add for error notification helper. | |
# config.error_notification_id = nil | |
# Series of attempts to detect a default label method for collection. | |
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ] | |
# Series of attempts to detect a default value method for collection. | |
# config.collection_value_methods = [ :id, :to_s ] | |
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none. | |
# config.collection_wrapper_tag = nil | |
# You can define the class to use on all collection wrappers. Defaulting to none. | |
# config.collection_wrapper_class = nil | |
# You can wrap each item in a collection of radio/check boxes with a tag, | |
# defaulting to :span. Please note that when using :boolean_style = :nested, | |
# SimpleForm will force this option to be a label. | |
# config.item_wrapper_tag = :span | |
# You can define a class to use in all item wrappers. Defaulting to none. | |
# config.item_wrapper_class = nil | |
# How the label text should be generated altogether with the required text. | |
# config.label_text = lambda { |label, required| "#{required} #{label}" } | |
# You can define the class to use on all labels. Default is nil. | |
config.label_class = 'control-label' | |
# You can define the class to use on all forms. Default is simple_form. | |
# config.form_class = :simple_form | |
# You can define which elements should obtain additional classes | |
# config.generate_additional_classes_for = [:wrapper, :label, :input] | |
# Whether attributes are required by default (or not). Default is true. | |
# config.required_by_default = true | |
# Tell browsers whether to use the native HTML5 validations (novalidate form option). | |
# These validations are enabled in SimpleForm's internal config but disabled by default | |
# in this configuration, which is recommended due to some quirks from different browsers. | |
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations, | |
# change this configuration to true. | |
config.browser_validations = false | |
# Collection of methods to detect if a file type was given. | |
# config.file_methods = [ :mounted_as, :file?, :public_filename ] | |
# Custom mappings for input types. This should be a hash containing a regexp | |
# to match as key, and the input type that will be used when the field name | |
# matches the regexp as value. | |
# config.input_mappings = { /count/ => :integer } | |
# Custom wrappers for input types. This should be a hash containing an input | |
# type as key and the wrapper that will be used for all inputs with specified type. | |
# config.wrapper_mappings = { string: :prepend } | |
# Default priority for time_zone inputs. | |
# config.time_zone_priority = nil | |
# Default priority for country inputs. | |
# config.country_priority = nil | |
# When false, do not use translations for labels. | |
# config.translate_labels = true | |
# Automatically discover new inputs in Rails' autoload path. | |
# config.inputs_discovery = true | |
# Cache SimpleForm inputs discovery | |
# config.cache_discovery = !Rails.env.development? | |
# Default class for inputs | |
# config.input_class = nil | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_action :set_user, only: [:edit, :update, :destroy] | |
before_action :authenticate_user! | |
# GET /users | |
def index | |
@users = User.all | |
end | |
# GET /users/new | |
def new | |
@user = User.new | |
end | |
# GET /users/1/edit | |
def edit | |
end | |
# POST /users | |
def create | |
@user = User.new(user_params) | |
if @user.save | |
redirect_to users_url | |
else | |
render action: 'new' | |
end | |
end | |
# PATCH/PUT /users/1 | |
def update | |
if user_params[:password].blank? | |
@user.update_without_password(user_params_without_password) | |
else | |
@user.update(user_params) | |
end | |
if @user.valid? | |
if @user == current_user | |
sign_in(@user, bypass: true) | |
end | |
redirect_to users_url | |
else | |
render action: 'edit' | |
end | |
end | |
# DELETE /users/1 | |
def destroy | |
@user.destroy | |
redirect_to users_url, notice: 'Usuário excluído.' | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_user | |
@user = User.find(params[:id]) | |
end | |
# Only allow a trusted parameter "white list" through. | |
def user_params | |
params.require(:user).permit(:name, :email, :password, :password_confirmation) | |
end | |
def user_params_without_password | |
user_params.delete(:password) | |
user_params.delete(:password_confirmation) | |
user_params | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 Editar usuário | |
== render 'form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= simple_form_for(@user) do |f| | |
= f.error_notification | |
.form-inputs | |
= f.input :name | |
= f.input :email | |
= f.input :password | |
= f.input :password_confirmation | |
.form-actions | |
= f.button :submit, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 Usuários | |
table.table.table-striped | |
thead | |
tr | |
th Nome | |
th Email | |
th | |
tboby | |
- @users.each do |user| | |
tr | |
td = user.name | |
td = user.email | |
td | |
.btn-group.pull-right | |
= link_to 'Editar', edit_user_path(user), class: 'btn btn-default btn-sm' | |
= link_to 'Excluir', user, data: {:confirm => 'Tem certeza?'}, :method => :delete, class: 'btn btn-default btn-sm' | |
br | |
= link_to 'Criar usuário', new_user_path, class: 'btn btn-primary' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 Criar usuário | |
== render 'form' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment