We made adjustments for the final task. At that time, the conditional expression has a special pattern of using both if and unless. I tried to challenge. I will post it as a memorandum.
This time it is described in haml.
sample.rb
#In the view file
.item-show-page__link-btn
-if @item.buyers.present?
%p SOLD OUT
-else
- unless user_signed_in? && @item.user_id == current_user.id
= link_to purchase_item_path(@item.id), class: "item-show-page__link" do
To purchase screen
- else
%p Seller cannot purchase
The contents of the method @item Contains listing information. buyers This is the method of purchase history.
if〜else If the purchase history ID exists, SOLD OUT is displayed.
unless~else
Nested inside the else of the if statement
doing. From there, the unless conditional expression is entered.
If the item you listed does not match your user ID, a link to the purchase screen will appear.
If not, it will appear as "Seller cannot purchase".
That is all.
Recommended Posts