I'm trying to get to grips with Rails and I'm stuck on getting an 8 question multi-choice question quiz working.
I think I understand the MVC side of things. Requests from the browser come through a controller. It asks for info from models, sends it to the views and returns the content to the browser (please correct me if I'm wrong).
I DON'T understand (very clearly, at least) how pages 'know' where to link to. I think, when you generate a resource, you're given a plethora of routes mapped to paths. I don't understand when those paths are relevant.
Could someone please explain to me (step-by-step, if necessary) how the submit button in a Devise form 'knows' where to link to?
My form, so far, looks like this:
<%= form_for([current_user]) do |f| %>
<p>
<%= f.check_box :quiz_answers %>
</p>
<p>
<%= f.submit("Get my results!") %>
</p>
<% end %>
I see nothing in there that NAMES a path or a route. How, then, is the link generated?
I have checked rake routes, but I don't think I'm appreciating what is significant about that list. If someone could explain the MEANING behind it, that would be great.
I will try to explain it.
There are several types of methods that you can send through web page:
-GET
-POST
-DELETE
-PUT
Get sends parameters through link. you can see its parameters in URL, for instance www.google.ba?you_are=user, you_are is parameter and its value is user.
Post sends parameters through package so you can't see anything in the url, yet informations are there.
Other methods are variations for POST method for restful service.
For your question, devise creates by default some routes that are not clearly visible in routes.rb. Any request that comes across your webpage goes to the routes.rb, checks where should it be delegated then send that to corresponding controller. Controller then takes parameters do some logic(delegates it to services and other things), prepares models for show and then delegates it to template. Then, template with all informations(rendered) is sent to web browser.
There is one thing to mention, resource or devise creates default actions for every method for corresponding action. In this case you just need to set model and it knows where to delegates it.
Here are my routes for devise ( some of them are custom):
new_user_session GET /users/sign_in(.:format) user_sessions#new
user_session POST /users/sign_in(.:format) user_sessions#create
destroy_user_session DELETE /users/sign_out(.:format) user_sessions#destroy
user_password POST /users/password(.:format) passwords#create
new_user_password GET /users/password/new(.:format) passwords#new
edit_user_password GET /users/password/edit(.:format) passwords#edit
PATCH /users/password(.:format) passwords#update
PUT /users/password(.:format) passwords#update
cancel_user_registration GET /users/cancel(.:format) users#cancel
user_registration POST /users(.:format) users#create
new_user_registration GET /users/sign_up(.:format) users#new
edit_user_registration GET /users/edit(.:format) users#edit
PATCH /users(.:format) users#update
PUT /users(.:format) users#update
DELETE /users(.:format) users#destroy
user_confirmation POST /users/confirmation(.:format) confirms#create
new_user_confirmation GET /users/confirmation/new(.:format) confirms#new
GET /users/confirmation(.:format) confirms#show
Use rake routes command in terminal to find out all your routes.
Related
I have voting established in my app via the Thumbs_Up gem. It is working perfectly on my localhost but when I try to up/down vote something on Heroku I get this error in my Heroku logs:
ActionController::RoutingError (No route matches [GET] "/jokes/wise-police-officer/vote_up"):
Here are my routes for the jokes model:
resources :jokes do
patch :approve, on: :member
patch :reject, on: :member
member do
post :vote_up
post :vote_down
end
end
Again, this is strange because it works fine in localhost. Has anyone had a similar problem?
Here's the HTML/ERB for the voting links:
<div class="width: 100%"><%= link_to " ", vote_up_joke_path(joke), class: 'upvote glyphicon glyphicon-chevron-up', method: :post, style: "margin-right: 0; margin-left: 0" %></div>
<div class="width: 100%"><h3 style="margin-top: 0; margin-bottom: 0"><strong><%= joke.plusminus %></strong></h3></div>
<div class="width: 100%"><%= link_to " ", vote_down_joke_path(joke), class: 'downvote glyphicon glyphicon-chevron-down', method: :post, style: "margin-right: 0; margin-left: 0" %></div>
And here's the entirety of my bundle exec rake routes output:
Prefix Verb URI Pattern Controller#Action
ckeditor /ckeditor Ckeditor::Engine
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PATCH /users(.:format) registrations#update
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
user GET /users/:id(.:format) users#show
home_index GET /home/index(.:format) home#index
root GET / home#index
home_lifehacks GET /home/lifehacks(.:format) home#lifehacks
home_mangear GET /home/mangear(.:format) home#mangear
home_gifthelper GET /home/gifthelper(.:format) home#gifthelper
home_commandments GET /home/commandments(.:format) home#commandments
gifts_babies GET /gifts/babies(.:format) gifts#babies
gifts_kids GET /gifts/kids(.:format) gifts#kids
gifts_teens GET /gifts/teens(.:format) gifts#teens
gifts_adults GET /gifts/adults(.:format) gifts#adults
principles GET /principles(.:format) principles#index
principles_intro GET /principles/intro(.:format) principles#intro
principles_intermediate GET /principles/intermediate(.:format) principles#intermediate
principles_advanced GET /principles/advanced(.:format) principles#advanced
principles_beef GET /principles/beef(.:format) principles#beef
principles_chicken GET /principles/chicken(.:format) principles#chicken
principles_pork GET /principles/pork(.:format) principles#pork
principles_fish GET /principles/fish(.:format) principles#fish
principles_recipes GET /principles/recipes(.:format) principles#recipes
archive_suggestion PATCH /suggestions/:id/archive(.:format) suggestions#archive
unarchive_suggestion PATCH /suggestions/:id/unarchive(.:format) suggestions#unarchive
suggestions GET /suggestions(.:format) suggestions#index
POST /suggestions(.:format) suggestions#create
suggestion DELETE /suggestions/:id(.:format) suggestions#destroy
suggestions_archives GET /suggestions/archives(.:format) suggestions#archives
man_tests POST /man_tests(.:format) man_tests#create
new_man_test GET /man_tests/new(.:format) man_tests#new
man_tests_fail GET /man_tests/fail(.:format) man_tests#fail
approve_joke PATCH /jokes/:id/approve(.:format) jokes#approve
reject_joke PATCH /jokes/:id/reject(.:format) jokes#reject
vote_up_joke POST /jokes/:id/vote_up(.:format) jokes#vote_up
vote_down_joke POST /jokes/:id/vote_down(.:format) jokes#vote_down
jokes GET /jokes(.:format) jokes#index
POST /jokes(.:format) jokes#create
new_joke GET /jokes/new(.:format) jokes#new
edit_joke GET /jokes/:id/edit(.:format) jokes#edit
joke GET /jokes/:id(.:format) jokes#show
PATCH /jokes/:id(.:format) jokes#update
PUT /jokes/:id(.:format) jokes#update
DELETE /jokes/:id(.:format) jokes#destroy
home_jokes GET /home/jokes(.:format) home#jokes
otherjokes_kids GET /otherjokes/kids(.:format) otherjokes#kids
otherjokes_mixed GET /otherjokes/mixed(.:format) otherjokes#mixed
otherjokes_men GET /otherjokes/men(.:format) otherjokes#men
otherjokes_comeback GET /otherjokes/comeback(.:format) otherjokes#comeback
approve_recipe PATCH /recipes/:id/approve(.:format) recipes#approve
reject_recipe PATCH /recipes/:id/reject(.:format) recipes#reject
vote_up_recipe POST /recipes/:id/vote_up(.:format) recipes#vote_up
vote_down_recipe POST /recipes/:id/vote_down(.:format) recipes#vote_down
recipes GET /recipes(.:format) recipes#index
POST /recipes(.:format) recipes#create
new_recipe GET /recipes/new(.:format) recipes#new
edit_recipe GET /recipes/:id/edit(.:format) recipes#edit
recipe GET /recipes/:id(.:format) recipes#show
PATCH /recipes/:id(.:format) recipes#update
PUT /recipes/:id(.:format) recipes#update
DELETE /recipes/:id(.:format) recipes#destroy
home_bbq GET /home/bbq(.:format) home#bbq
other_recipes_all GET /other_recipes/all(.:format) other_recipes#all
other_recipes_beef GET /other_recipes/beef(.:format) other_recipes#beef
other_recipes_chicken GET /other_recipes/chicken(.:format) other_recipes#chicken
other_recipes_fish GET /other_recipes/fish(.:format) other_recipes#fish
other_recipes_other_meat GET /other_recipes/other_meat(.:format) other_recipes#other_meat
other_recipes_veggies GET /other_recipes/veggies(.:format) other_recipes#veggies
approve_rule PATCH /rules/:id/approve(.:format) rules#approve
reject_rule PATCH /rules/:id/reject(.:format) rules#reject
vote_up_rule POST /rules/:id/vote_up(.:format) rules#vote_up
vote_down_rule POST /rules/:id/vote_down(.:format) rules#vote_down
rules GET /rules(.:format) rules#index
POST /rules(.:format) rules#create
new_rule GET /rules/new(.:format) rules#new
edit_rule GET /rules/:id/edit(.:format) rules#edit
rule GET /rules/:id(.:format) rules#show
PATCH /rules/:id(.:format) rules#update
PUT /rules/:id(.:format) rules#update
DELETE /rules/:id(.:format) rules#destroy
reminders GET /reminders(.:format) reminders#index
POST /reminders(.:format) reminders#create
new_reminder GET /reminders/new(.:format) reminders#new
edit_reminder GET /reminders/:id/edit(.:format) reminders#edit
reminder GET /reminders/:id(.:format) reminders#show
PATCH /reminders/:id(.:format) reminders#update
PUT /reminders/:id(.:format) reminders#update
DELETE /reminders/:id(.:format) reminders#destroy
Routes for Ckeditor::Engine:
pictures GET /pictures(.:format) ckeditor/pictures#index
POST /pictures(.:format) ckeditor/pictures#create
picture DELETE /pictures/:id(.:format) ckeditor/pictures#destroy
attachment_files GET /attachment_files(.:format) ckeditor/attachment_files#index
POST /attachment_files(.:format) ckeditor/attachment_files#create
attachment_file DELETE /attachment_files/:id(.:format) ckeditor/attachment_files#destroy
It's submitting a 'get' request and needs to be submitting a post request. Be sure you specify method: :post in your link_to call that handles "up votes".
I am 99% sure that link_to will always generate a get request, regardless you put a method :post in it.
Can you please share you log file details?
Here is something I tried on my end:
= link_to "Test", "/public/create", method: :post
And here is my log output:
Started GET "/public/create" for 127.0.0.1 at 2016-10-13 18:22:18 +0000
here is my route:
root to: 'public#index'
post "public/create", to: "public#create"
Make sure you have following in your application.js
//= require jquery
//= require jquery_ujs
jquery-ujs makes non-GET requests from hyperlinks. Even if link_to method produces proper html with data-method=post you need jquery-ujs to make non-GET requests other wise your links will naturally create GET request.
I contacted heroku support and they had a similar answer to #AjitSingh in recommending I use AJAX:
I see what you mean. Rather than relying on tags, I would suggest
making AJAX calls to do a proper POST request, using buttons or forms.
However, AJAX is a bit above my skill level right now. I also found this little gem (no pun intended) on the ROR API about using link_to:
method: symbol of HTTP verb - This modifier will dynamically create an
HTML form and immediately submit the form for processing using the
HTTP verb specified. Useful for having links perform a POST operation
in dangerous actions like deleting a record (which search bots can
follow while spidering your site). Supported verbs are :post, :delete,
:patch, and :put. Note that if the user has JavaScript disabled, the
request will fall back to using GET. If href: '#' is used and the user
has JavaScript disabled clicking the link will have no effect. If you
are relying on the POST behavior, you should check for it in your
controller's action by using the request object's methods for post?,
delete?, patch?, or put?.
Finally, I ended up consulting the advice of this SO post and using button_to instead of link_to and it fixed the issue. Whew.
A RoR beginner here. I am trying to implement a page 'My Products' to show all products added by current user. Currently I have set my 'All Products' page as my index root "products#index". My Product has Controller but my User does not not Controller because I am using Devise. I have a few questions which I still couldnt get it right.
Because currently
Product
belongs_to :user
User
has_many :products
routes
devise_for :users
resources :products
rake routes I have
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PATCH /products/:id(.:format) products#update
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
Currently what I have in mind to achieve this:
Create a UserController to have #user = User.all then because with association I can use #user.product. (I saw some people said that I shouldn't create new controller because of Devise?) However, I tried to test with rails console before doing the implementation.
product = Product.first
product.user #here I get all details about user
user = User.first
user.product #here I get error. Why it works for product to find user but not both ways?
Next, this then makes me wonder how do I create configure the route to get path /users/:id/products . Should I use a nested resource?
Next question, I tried to have
resources :users do
resources :products
end
resources :products
I typed in rake routes again. I am confused
user_products GET /users/:user_id/products(.:format) products#index
products GET /products(.:format) products#index
Question:
Can 2 path has the same Controller#Action?
user_products_path and products_path are 2 different path where user_products_path represents user's product. and products_path represents all products
Sorry for the long post.I really wish to clarify those things. Thanks a lot if you could help!! :)
user.product #here I get error. Why it works for product to find user but not both ways?
As User has_many :products, you need to use correct association name as:
user.products # it will give you all products of an user
Can 2 path has the same Controller#Action?
In short, YES. You can specify controller and action name explicitly in your route.rb like:
get 'users/:id/products' => 'products#index', :as => :user_products_path
Note that in your case, it will be going into products#index by default also.
user_products_path and products_path are 2 different path where user_products_path represents user's product. and products_path represents all products
Correct, it's absolutely fine. As you are using devise, you don't need to use id parameter coming from the URL i.e. users/:id/products. You can get the user directly from current_user, which is better in terms of security also. Keep in mind that if you have admin role who can see details of every user then you will need to manage id in that case.
Because you're just starting out, I'll keep this example simple with having easy to read logic. However, there are better ways to configure and optimize this so that you're not relying on if statements in your controller.
class ProductsController < ApplicationController
def index
if params[:user_id]
#user = User.find(params[:user_id])
#products = #user.products.all
else
#products = Product.all
end
end
end
One reason why this is bad practice is that you're relying on the user_id param to be valid. If the user_id param is not valid, then the second line #products = #user.products.all will return undefined method for Nil class.
Also, in your views, if you reference #user then you will get an error if you're just listing out all products.
Also, there isn't any security being done where anyone can see anyone's products if they know or try to guess the user's id.
However, this should work in your instance. You may also want to consider that if the user_id is present to then call current_user.products.all so that it will only return the current user's products instead of the particular user_id's. However, it is really up to how you're designing the application that will determine the best route to take.
What I'll typically do is if the /products route should be for the administrative level, I'll namespace it and put the appropriate security around the namespacing so that it does not allow general users to access it, but rather only administrators of the site.
I know this question has been asked quite a few times, but somehow it's not working for me. I would like the user to be redirected to a specific page after log in (using Devise). I'm using Rails 3.2 and Ruby 4.
As it is the user get redirected to:
- After login they get redirected to the root, if the user got to the login page from one of the pages controlled by the controller of which the root path is part of. These pages do not require authorization.
- After login they get redirected to the requested page, if the user automatically got to the login page by clicking on a page that requires authorization.
To redirect the user after login to a specific page, I understand that you need to add to the controller some lines. To the controller that is controlling the pages that required authorization I added:
class AccountsController < ApplicationController
before_filter :authenticate_user!
def user1_home
end
def user2_home
end
def user3_home
end
protected
def after_sign_in_path_for(resource)
'accounts/user1_home'
end
end
However, this didn't change anything. I also tried it with def after_sign_in_path_for(resource) 'accounts#user1_home_path' end
Should I perhaps also change something in routes.rb?
My routes are:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
toc GET /toc(.:format) pages#toc
stakeholder GET /stakeholder(.:format) pages#stakeholder
about GET /about(.:format) pages#about
doelgroep_onderneming GET /doelgroep_onderneming(.:format) pages#doelgroep_onderneming
doelgroep_ngo GET /doelgroep_ngo(.:format) pages#doelgroep_ngo
doelgroep_se GET /doelgroep_se(.:format) pages#doelgroep_se
partnership GET /partnership(.:format) pages#partnership
contact GET /contact(.:format) pages#contact
account_stakeholder GET /account/stakeholder(.:format) accounts#stakeholder_home
account_business GET /account/business(.:format) accounts#business_home
account_admin GET /account/admin(.:format) accounts#admin_home
root / pages#index
You definitely shouldn't be defining methods per user in the Accounts controller.
Devise has instructions on github for accomplishing this: https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in
You need to move after_sign_in_path_for to the ApplicationController class and you shouldn't have 'accounts/user1_home'. To go to the right url for each use you should have something along the lines of user_path(#user) but I don't have enough of your code to know exactly what to use. You should run in a console window the rake routes command to see what you routes you have made available. Read more about routing at: http://guides.rubyonrails.org/routing.html
Yes. Set the following at any point (before or after login):
session["user_return_to"] = request.original_url # Will redirect the user to where they came from
If it's an authenticated page they tried to access before logging in you want to redirect to then you can simply do it this way in your ApplicationController:
def after_sign_in_path_for(resource)
if session[:user_return_to] == nil
your_actual_next_path
else
super
end
end
I'm setting up my first rails application and I have a question for an experienced developer. I use devise for my user authentication system. I'm not up on the verbiage yet, so forgive me.
The user will have a dashboard when they log in. Is it better to use the generate scaffold tool to setup a single controller for the dashboard (and use if statements to differentiate), or create the dashboard page under the /students and /teachers (having two separate controllers)?
I'm looking to avoid wasting time or having to backtrack my application if I notice one method won't allow me to achieve something down the road. I'm leaning towards separating them.
Here is my rake routes for you to see how I've got stuff setup so far:
rake routes
Prefix Verb URI Pattern Controller#Action
landing_index GET /landing/index(.:format) landing#index
new_teacher_session GET /teachers/sign_in(.:format) devise/sessions#new
teacher_session POST /teachers/sign_in(.:format) devise/sessions#create
destroy_teacher_session DELETE /teachers/sign_out(.:format) devise/sessions#destroy
teacher_password POST /teachers/password(.:format) devise/passwords#create
new_teacher_password GET /teachers/password/new(.:format) devise/passwords#new
edit_teacher_password GET /teachers/password/edit(.:format) devise/passwords#edit
PATCH /teachers/password(.:format) devise/passwords#update
PUT /teachers/password(.:format) devise/passwords#update
cancel_teacher_registration GET /teachers/cancel(.:format) devise/registrations#cancel
teacher_registration POST /teachers(.:format) devise/registrations#create
new_teacher_registration GET /teachers/sign_up(.:format) devise/registrations#new
edit_teacher_registration GET /teachers/edit(.:format) devise/registrations#edit
PATCH /teachers(.:format) devise/registrations#update
PUT /teachers(.:format) devise/registrations#update
DELETE /teachers(.:format) devise/registrations#destroy
new_student_session GET /students/sign_in(.:format) devise/sessions#new
student_session POST /students/sign_in(.:format) devise/sessions#create
destroy_student_session DELETE /students/sign_out(.:format) devise/sessions#destroy
student_password POST /students/password(.:format) devise/passwords#create
new_student_password GET /students/password/new(.:format) devise/passwords#new
edit_student_password GET /students/password/edit(.:format) devise/passwords#edit
PATCH /students/password(.:format) devise/passwords#update
PUT /students/password(.:format) devise/passwords#update
cancel_student_registration GET /students/cancel(.:format) devise/registrations#cancel
student_registration POST /students(.:format) devise/registrations#create
new_student_registration GET /students/sign_up(.:format) devise/registrations#new
edit_student_registration GET /students/edit(.:format) devise/registrations#edit
PATCH /students(.:format) devise/registrations#update
PUT /students(.:format) devise/registrations#update
DELETE /students(.:format) devise/registrations#destroy
root GET / landing#index
So again, do you think it's better to have both the student's dashboard and the teacher's dashboard be separate, or just have one dashboard and use if statements to differentiate based on the user's type (using 0 & 1 to indicate whether they are a student or teacher)?
Thanks in advance!
If the data that you want to display to each type of user are similar, you could use the same controller and load different partials based on the type of the user.
When I access /users/registration/sign_up in my app via the browser (GET) a page renders. When I do the same thing via POST (either by submitting a form w/ the target /users/registration/sign_up or with ajax) my app returns the following error:
Unknown action
The action 'registration' could not be found for UsersController
I am using devise for authentication and creating a devise route for my User model using:
devise_for :users
This path should route to the devise/registrations_controller where i expect it to execute the new method (it currently does for a GET request). Maybe rails, understanding the request is a POST request automatically directs it to the create method but I don't think this is the issue because I start the debugger first thing in the create method and the debugger is not starting in my terminal before I receive this error.
Can anyone with experience with devise decipher what's going on? I'm happy to provide more info if necessary. Thanks.
Devise adds routes to your Rails app, which you can see by running rake routes from a terminal:
new_user_session GET /users/sign_in(.:format)
user_session POST /users/sign_in(.:format)
destroy_user_session GET /users/sign_out(.:format)
user_password POST /users/password(.:format)
new_user_password GET /users/password/new(.:format)
edit_user_password GET /users/password/edit(.:format)
PUT /users/password(.:format)
user_registration POST /users(.:format)
new_user_registration GET /users/sign_up(.:format)
edit_user_registration GET /users/edit(.:format)
PUT /users(.:format)
DELETE /users(.:format)
root /(.:format)
And as you discovered, there is a GET /users/sign_up but no POST /users/sign_up. When creating Devise expects POST /users, for which you can use the helper method user_registration_path. This gets handled by Devise::RegistrationsController#create.