Good evening Aloha man, Yasunori!
Today I'm going to talk about the stumbling block I encountered while modifying the devise view file.
However, if you have the premise, please refer to it! !!
Gem while creating an application in Rails
Those who use devise and also convert html.erb
to html.haml
with haml-rails etc.
I wanted to add a name input field to the view file of the new registration page of devise and modified the code.
ruby:views/users/registrations/new.html.haml
%h2 Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= render "users/shared/error_messages", resource: resource
.field
= f.label :name
%br/
= f.text_field :name, autofocus: true
.field
= f.label :email
%br/
= f.email_field :email, autofocus: true, autocomplete: "email"
.field
= f.label :password
- if @minimum_password_length
%em
(#{@minimum_password_length} characters minimum)
%br/
= f.password_field :password, autocomplete: "new-password"
.field
= f.label :password_confirmation
%br/
= f.password_field :password_confirmation, autocomplete: "new-password"
.actions
= f.submit "Sign up"
= render "users/shared/links"
So, add the: name field and it's perfect! !! I thought ...
...e? Has nothing changed? ?? that? ?? ??
Did you make a mistake in the view file to be corrected? Even if I check it, it definitely says registrations ...
<img width="1500
px "alt =" file name "src =" https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/699622/9a05c09f-fbac-c5cb-b3c7-bdbae3798fcb.jpeg ">
that! ??
For some reason, I'm referring to new.html.erb
! ??
Moreover, the reference destination is ʻapp / views / deviseregistrations / new.html.erb`! ??
When I looked it up, I could see the cause.
Due to the configuration of my application, devise had a User model, so when I generated the view file of devise, I typed the command $ rails g devise: views users
, but this seems to be the cause.
If there is no model of devise other than ʻUser model in the first place, it seems that only
$ rails g devise: views` was enough.
The directory structure of the generated view file will change a little.
Specifically, if you type the command $ rails g devise: views users
,
Directory and view files will be created under ʻapp / views / users / `.
On the other hand, if you type the command $ rails g devise: views
Directory and view files will be created under ʻapp / views / devise`.
_devise directory _...
<img width="1500 px "alt =" file name "src =" https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/699622/9a05c09f-fbac-c5cb-b3c7-bdbae3798fcb.jpeg ">
This is it! !!
Yes, I was committing when I generated the view file, so after deleting the commit history and retyping the command, I modified the code in the new view file.
Then ...
Alright! !! A name input field has been added! !!
The reference destination is also properly new.html.haml
! !!
When generating a view file of devise, __basic __ $ rails g devise: views
is OK !!
Please be careful, too! !!
Recommended Posts