Skip to content

Commit 862f64a

Browse files
committed
Configure devise with name update parameter
1 parent f16c947 commit 862f64a

File tree

5 files changed

+75
-49
lines changed

5 files changed

+75
-49
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ end
7676

7777
gem 'tailwindcss-rails', '~> 2.0'
7878

79-
gem "devise", "~> 4.8"
79+
gem 'devise', '~> 4.8'

app/controllers/application_controller.rb

+19
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@
22

33
# Apllication controller
44
class ApplicationController < ActionController::Base
5+
protect_from_forgery with: :exception
6+
before_action :update_allowed_parameters, if: :devise_controller?
7+
8+
protected
9+
10+
def update_allowed_parameters
11+
devise_parameter_sanitizer.permit(:sign_up) do |u|
12+
u.permit(:name, :email, :password, :password_confirmation)
13+
end
14+
devise_parameter_sanitizer.permit(:account_update) do |u|
15+
u.permit(:name, :email, :password, :current_password, :password_confirmation)
16+
end
17+
end
18+
19+
private
20+
21+
def after_sign_up_path_for(_resource_or_scope)
22+
root
23+
end
524
end

app/views/devise/registrations/new.html.erb

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
44
<%= render "devise/shared/error_messages", resource: resource %>
55

6+
<div class="field">
7+
<%= f.label :name %><br />
8+
<%= f.text_field :name %>
9+
</div>
10+
611
<div class="field">
712
<%= f.label :email %><br />
813
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>

spec/rails_helper.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# frozen_string_literal: true
2+
13
# This file is copied to spec/ when you run 'rails generate rspec:install'
24
require 'spec_helper'
35
ENV['RAILS_ENV'] ||= 'test'
46
require_relative '../config/environment'
57
# Prevent database truncation if the environment is production
6-
abort("The Rails environment is running in production mode!") if Rails.env.production?
8+
abort('The Rails environment is running in production mode!') if Rails.env.production?
79
require 'rspec/rails'
810
# Add additional requires below this line. Rails is not loaded until this point!
911

spec/spec_helper.rb

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
24
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
35
# The generated `.rspec` file contains `--require spec_helper` which will cause
@@ -44,51 +46,49 @@
4446
# triggering implicit auto-inclusion in groups with matching metadata.
4547
config.shared_context_metadata_behavior = :apply_to_host_groups
4648

47-
# The settings below are suggested to provide a good initial experience
48-
# with RSpec, but feel free to customize to your heart's content.
49-
=begin
50-
# This allows you to limit a spec run to individual examples or groups
51-
# you care about by tagging them with `:focus` metadata. When nothing
52-
# is tagged with `:focus`, all examples get run. RSpec also provides
53-
# aliases for `it`, `describe`, and `context` that include `:focus`
54-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55-
config.filter_run_when_matching :focus
56-
57-
# Allows RSpec to persist some state between runs in order to support
58-
# the `--only-failures` and `--next-failure` CLI options. We recommend
59-
# you configure your source control system to ignore this file.
60-
config.example_status_persistence_file_path = "spec/examples.txt"
61-
62-
# Limits the available syntax to the non-monkey patched syntax that is
63-
# recommended. For more details, see:
64-
# https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
65-
config.disable_monkey_patching!
66-
67-
# Many RSpec users commonly either run the entire suite or an individual
68-
# file, and it's useful to allow more verbose output when running an
69-
# individual spec file.
70-
if config.files_to_run.one?
71-
# Use the documentation formatter for detailed output,
72-
# unless a formatter has already been configured
73-
# (e.g. via a command-line flag).
74-
config.default_formatter = "doc"
75-
end
76-
77-
# Print the 10 slowest examples and example groups at the
78-
# end of the spec run, to help surface which specs are running
79-
# particularly slow.
80-
config.profile_examples = 10
81-
82-
# Run specs in random order to surface order dependencies. If you find an
83-
# order dependency and want to debug it, you can fix the order by providing
84-
# the seed, which is printed after each run.
85-
# --seed 1234
86-
config.order = :random
87-
88-
# Seed global randomization in this process using the `--seed` CLI option.
89-
# Setting this allows you to use `--seed` to deterministically reproduce
90-
# test failures related to randomization by passing the same `--seed` value
91-
# as the one that triggered the failure.
92-
Kernel.srand config.seed
93-
=end
49+
# The settings below are suggested to provide a good initial experience
50+
# with RSpec, but feel free to customize to your heart's content.
51+
# # This allows you to limit a spec run to individual examples or groups
52+
# # you care about by tagging them with `:focus` metadata. When nothing
53+
# # is tagged with `:focus`, all examples get run. RSpec also provides
54+
# # aliases for `it`, `describe`, and `context` that include `:focus`
55+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56+
# config.filter_run_when_matching :focus
57+
#
58+
# # Allows RSpec to persist some state between runs in order to support
59+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
60+
# # you configure your source control system to ignore this file.
61+
# config.example_status_persistence_file_path = "spec/examples.txt"
62+
#
63+
# # Limits the available syntax to the non-monkey patched syntax that is
64+
# # recommended. For more details, see:
65+
# # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
66+
# config.disable_monkey_patching!
67+
#
68+
# # Many RSpec users commonly either run the entire suite or an individual
69+
# # file, and it's useful to allow more verbose output when running an
70+
# # individual spec file.
71+
# if config.files_to_run.one?
72+
# # Use the documentation formatter for detailed output,
73+
# # unless a formatter has already been configured
74+
# # (e.g. via a command-line flag).
75+
# config.default_formatter = "doc"
76+
# end
77+
#
78+
# # Print the 10 slowest examples and example groups at the
79+
# # end of the spec run, to help surface which specs are running
80+
# # particularly slow.
81+
# config.profile_examples = 10
82+
#
83+
# # Run specs in random order to surface order dependencies. If you find an
84+
# # order dependency and want to debug it, you can fix the order by providing
85+
# # the seed, which is printed after each run.
86+
# # --seed 1234
87+
# config.order = :random
88+
#
89+
# # Seed global randomization in this process using the `--seed` CLI option.
90+
# # Setting this allows you to use `--seed` to deterministically reproduce
91+
# # test failures related to randomization by passing the same `--seed` value
92+
# # as the one that triggered the failure.
93+
# Kernel.srand config.seed
9494
end

0 commit comments

Comments
 (0)