##Overview
This time, I would like to write about an implementation that uses helper methods to conditionally branch when writing a view file.
In particular, I want to display this part when "when the product is not purchased" on the flea market apps. Or I want to hide this display when "the user is not logged in". I will implement a function like that.
ruby:xxx.html.erb
<% if user_signed_in? && current_user.id == @product.user_id %>
This is the part below the description "Only if the user is logged in and that user is the user who listed this item." It is a description to be displayed.
ruby:xxx.html.erb
<% if @item.item_purchase.present? %>
This is the part below the description "Only if data exists in the item_purchase column of @item" It is a description to be displayed.
Not only written here, I think that there are various implementations, but I will output it as the work content.
Recommended Posts