前提・実現したいこと
deviseのgemにもともとある項目(name)(e-mail)(password)(password確認)に
(code)項目を作たい。(password)(code)で二重に確認をして出勤できるようにしたいから。
ここに質問の内容を詳しく書いてください。
ruby on railsで勤怠システムを作っています。
devise機能に追加したい項目(コード)項目を実装中に以下のエラーメッセージが発生しました。
経緯はdeviseのgemを利用してプラスで本人確認の項目を付けようと考えたからです。
発生している問題・エラーメッセージ
NoMethodError in Devise::Registrations#new
エラーメッセージ
Showing /Users/gradius/last_model/kintaikun2/app/views/devise/registrations/new.html.haml where line #34 raised:
undefined method `code_field' for #ActionView::Helpers::FormBuilder:0x00007fecebdb24c0
Did you mean? color_field
date_field
phone_field
該当のソースコード
ruby
view/devise/registrations
.AccountPage
.AccountPage__title
%h2 Create Account
%h5 新規アカウントの作成
= render "devise/shared/links"
.AccountPage__form
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= devise_error_messages!
.FormField
.FormField__label--normal
= f.label :name
.FormField__input--normal
= f.text_field :name, autofocus: true
.FormField
.FormField__label--normal
= f.label :email
.FormField__input--normal
= f.email_field :email
.FormField
.FormField__label--normal
= f.label :password
%i (英数字8文字以上)
.FormField__input--normal
= f.password_field :password, autocomplete: "off"
.FormField
.FormField__label--normal
= f.label :password_confirmation
.FormField__input--normal
= f.password_field :password_confirmation, autocomplete: "off"
.FormField
.FormField__label--normal
= f.label :code
.FormField__input--normal
= f.code_field :code
.actions
= f.submit "Create Account", class: 'Button UserButton'
db/migrate/devise_create_users.rb
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :name, null: false
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.integer :code, null: false
t.references :place, foreign_key: true
## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable # t.integer :sign_in_count, default: 0, null: false # t.datetime :current_sign_in_at # t.datetime :last_sign_in_at # t.string :current_sign_in_ip # t.string :last_sign_in_ip ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at t.timestamps null: false end add_index :users, :name, unique: true add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true add_colmun :users, :code, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true
end
end
ここに問題に対して試したことを記載してください。
devise_create_users.rbに
add_column :users, :code, :integerを表記し
ターミナルで rails db:migrateを行った
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/12/07 10:05
2020/12/07 10:08