teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

user.rbの追加

2020/09/04 03:33

投稿

75ks
75ks

スコア4

title CHANGED
File without changes
body CHANGED
@@ -144,4 +144,36 @@
144
144
  <% end %>
145
145
  </div>
146
146
  </div>
147
+ ```
148
+
149
+ --------追記--------
150
+
151
+ ```userrb
152
+ class User < ApplicationRecord
153
+ # Include default devise modules. Others available are:
154
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
155
+ devise :database_authenticatable, :registerable,
156
+ :recoverable, :rememberable, :validatable
157
+
158
+ extend ActiveHash::Associations::ActiveRecordExtensions
159
+ belongs_to_active_hash :gender
160
+ has_many :posts, dependent: :destroy
161
+ has_many :comments, dependent: :destroy
162
+ has_many :favorites, dependent: :destroy
163
+ has_many :favorite_posts, through: :favorites, source: :post
164
+
165
+ with_options presence: true do
166
+ validates :nickname
167
+ validates :gender_id
168
+ end
169
+
170
+ validates :email, uniqueness: true
171
+
172
+ validates :nickname, length: { maximum: 8, message: "は8文字以下にしてください" }
173
+
174
+ validates :gender_id, numericality: { other_than: 1, message: "を選択してください" }
175
+
176
+ half_width_alphanumeric = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]{6,100}+\z/i
177
+ validates :password, presence: true, format: { with: half_width_alphanumeric, message: "に半角英数字を使用してください" }
178
+ end
147
179
  ```

1

タイトルをわかりやすく変更

2020/09/04 03:33

投稿

75ks
75ks

スコア4

title CHANGED
@@ -1,1 +1,1 @@
1
- deviseを使ったユーザー編集機能が実装できない
1
+ deviseを使ったパスワードなしユーザー編集機能が実装できない
body CHANGED
File without changes