質問編集履歴

1

モデルの情報を追記しました

2021/05/16 15:41

投稿

hiroki1121
hiroki1121

スコア2

test CHANGED
File without changes
test CHANGED
@@ -117,3 +117,127 @@
117
117
  VSCode
118
118
 
119
119
  MySQL
120
+
121
+
122
+
123
+ ### post.rb
124
+
125
+ ```ここに言語を入力
126
+
127
+ class Post < ApplicationRecord
128
+
129
+ has_one_attached :image
130
+
131
+ belongs_to :contracted_side_user
132
+
133
+ has_many :favorites, dependent: :destroy
134
+
135
+ has_many :reviews, dependent: :destroy
136
+
137
+ has_many :consignment_side_users, through: :favirites
138
+
139
+ has_many :consignment_side_users, through: :reviews
140
+
141
+
142
+
143
+ VALID_POST_CODE_REGEX = /\A\d{3}-\d{4}\z/.freeze
144
+
145
+ VALID_EAMIL_REGEX = /\A[A-Za-z0-9.+_-]+@([A-Za-z0-9_-]+.)+[A-Za-z]{2,}\z/.freeze
146
+
147
+ VALID_PHONE_NUMBER_REGEX = /\A\d{10,11}\z/.freeze
148
+
149
+ VALID_COMPANY_URL_REGEX = /\A#{URI::regexp(%w(http https))}\z/.freeze
150
+
151
+
152
+
153
+ with_options presence: true do
154
+
155
+ validates :image
156
+
157
+ validates :industry_id, numericality: { other_than: 1, message: 'は---以外を選択してください' }
158
+
159
+ validates :company_name
160
+
161
+ validates :post_code, format: { with: VALID_POST_CODE_REGEX, message: 'を正しく入力してください' }
162
+
163
+ validates :prefecture_id, numericality: { other_than: 1, message: 'は---以外を選択してください' }
164
+
165
+ validates :address
166
+
167
+ validates :employee_number
168
+
169
+ validates :representative_name
170
+
171
+ validates :email, format: { with: VALID_EAMIL_REGEX, message: 'を正しく入力してください' }
172
+
173
+ validates :represent_phone_number, format: { with: VALID_PHONE_NUMBER_REGEX, message: 'を正しく入力してください' }
174
+
175
+ validates :business_detail, length: { maximum: 500 }
176
+
177
+ end
178
+
179
+ validates :company_url, format: { with: VALID_COMPANY_URL_REGEX, message: 'を正しく入力してください' }, allow_blank: true
180
+
181
+ validates :direct_phone_number, format: { with: VALID_PHONE_NUMBER_REGEX, message: 'を正しく入力してください' }, allow_blank: true
182
+
183
+
184
+
185
+ extend ActiveHash::Associations::ActiveRecordExtensions
186
+
187
+ belongs_to :industry
188
+
189
+ belongs_to :prefecture
190
+
191
+ end
192
+
193
+ ```
194
+
195
+ ### contracted_side_user.rb
196
+
197
+ ```ここに言語を入力
198
+
199
+ class ContractedSideUser < ApplicationRecord
200
+
201
+ # Include default devise modules. Others available are:
202
+
203
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
204
+
205
+ devise :database_authenticatable, :registerable,
206
+
207
+ :recoverable, :rememberable, :validatable
208
+
209
+
210
+
211
+ has_many :posts
212
+
213
+
214
+
215
+ VALID_EAMIL_REGEX = /\A[A-Za-z0-9.+_-]+@([A-Za-z0-9_-]+.)+[A-Za-z]{2,}\z/.freeze
216
+
217
+ VALID_PASSWORD_REGEX = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]+\z/i.freeze
218
+
219
+ VALID_NAME_REGEX = /\A[ぁ-んァ-ヶ一-龥々ー]+\z/.freeze
220
+
221
+ VALID_NAME_RUBY_REGEX = /\A[ァ-ヶ]+\z/.freeze
222
+
223
+
224
+
225
+ with_options presence: true do
226
+
227
+ validates :email, uniqueness: { case_sensitive: true }, format: { with: VALID_EAMIL_REGEX, message: 'を正しく入力してください' }
228
+
229
+ validates :password, format: { with: VALID_PASSWORD_REGEX, message: 'を正しく入力してください' }
230
+
231
+ validates :last_name, format: { with: VALID_NAME_REGEX, message: 'を正しく入力してください' }
232
+
233
+ validates :first_name, format: { with: VALID_NAME_REGEX, message: 'を正しく入力してください' }
234
+
235
+ validates :last_name_ruby, format: { with: VALID_NAME_RUBY_REGEX, message: 'を正しく入力してください' }
236
+
237
+ validates :first_name_ruby, format: { with: VALID_NAME_RUBY_REGEX, message: 'を正しく入力してください' }
238
+
239
+ end
240
+
241
+ end
242
+
243
+ ```