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

質問編集履歴

2

ファイルを追加しました

2020/06/07 15:49

投稿

mayok
mayok

スコア12

title CHANGED
@@ -1,1 +1,1 @@
1
- rails db:migrate:resetきない
1
+ rails db:migrate:resetで引数エラーが出る
body CHANGED
@@ -61,6 +61,48 @@
61
61
  down 20200607084912 Create relationships
62
62
  ```
63
63
 
64
+ ```
65
+ (user.rb)
66
+ class User < ApplicationRecord
67
+ devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable, :omniauthable
68
+
69
+ has_many :microposts, dependent: :destroy
70
+ has_many :likes, dependent: :destroy
71
+ has_many :liked_posts, through: :likes, source: :micropost
72
+ has_many :bookmarks, dependent: :destroy
73
+ has_many :active_relationships, class_name: "Relationship",
74
+ foreign_key: "follower_id",
75
+ dependent: :destroy
76
+ has_many :passive_relationships, class_name: "Relationship",
77
+ foreign_key: "followed_id",
78
+ dependent: :destroy
79
+ has_many :following, through: :active_relationships, source: :followed
80
+ has_many :followers, through: :passive_relationships, source: :follower
81
+
82
+ validates :name, presence: true, length: { maximum: 50 }
83
+ validates :email, presence: true, length: { maximum: 255 }
84
+
85
+ def self.guest
86
+ find_or_create_by!(name: 'guest', email: 'guest@example.com') do |user|
87
+ user.password = SecureRandom.urlsafe_base64
88
+ user.confirmed_at = Time.zone.now
89
+ end
90
+ end
91
+
92
+ def follow(other_user)
93
+ following << other_user
94
+ end
95
+
96
+ def unfollow(other_user)
97
+ active_relationships.find_by(followed_id: other_user.id).destroy
98
+ end
99
+
100
+ def following?(other_user)
101
+ following.include?(other_user)
102
+ end
103
+ end
104
+ ```
105
+
64
106
  ### 試したこと
65
107
  記述したエラーが出力される前に
66
108
  ```Mysql2::Error: Can't DROP 'time'; check that column/key exists```というエラーが出ていました。

1

タイトルを変更

2020/06/07 15:49

投稿

mayok
mayok

スコア12

title CHANGED
@@ -1,1 +1,1 @@
1
- ArgumentError: wrong number of argumentsエラー解消できない
1
+ rails db:migrate:resetができない
body CHANGED
File without changes