[Caution !!] Precautions when converting Rails devise and view files to haml

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! !!

Premise

Gem while creating an application in Rails Those who use devise and also convert html.erb to html.haml with haml-rails etc.

Status

ファイル名

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.

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.

What is the difference between the two commands?

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! !!

Conclusion

When generating a view file of devise, __basic __ $ rails g devise: views is OK !!

Please be careful, too! !!

Recommended Posts

[Caution !!] Precautions when converting Rails devise and view files to haml
[Rails] How to edit and customize devise view and controller
[Rails] [Memo] When to add = to <%%> and when not
Automatically apply bootstrap style to devise view files
Precautions when converting from decimal number to binary number
Summary of good points and precautions when converting Java Android application to Kotlin
[Rails] About error resolution when installing devise and activeadmin
[Rails] Precautions when comparing date and time with DateTime
[Rails] How to install devise
[Java] Shallow copy and deep copy when converting an array to List
[Rails] Add a confirmation screen and a completion screen to devise membership registration.
[Rails 5] How to display the password change screen when using devise
How to write the view when Vue is introduced in Rails?
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Java] Tips and error issues when converting from double to Big Decimal
[Rails] devise customization. How to change the redirect page after user registration and editing, and how to skip password input when editing
[JSR-310 Date and Time API] Precautions for format definition when converting from Japanese calendar character string to date type