With Ruby on Rails, you can buy and sell with individuals like time tickets I want to create a service like this.
In this process, we would like to make specifications so that "if a user has already reviewed the user, you can edit it instead of posting a review" in order to implement the review function.

I'm getting an error when using the if statement on the screen to determine if the user has reviewed.
Rails tutorial Partial of follow/follower cancellation form Is not displayed well.

undefined method `review_content? 'for #<User: 0x007fe1d210ac28>
Did you mean? Review_content
               review_content =
               reviewed_content =
<% if current_user.review_content? (@ user)%>
  <% = link_to @ user.username + "Edit reviews", edit_review_path%>
<% elsif @user! = current_user%>
  <% = link_to @ user.username + "Write a review", new_review_path%>
<% end%>
class UsersController<ApplicationController
  def show
    @user = User.find (params [: id])
    @reviews = @ user.passive_reviews

User model

class User<ApplicationRecord
  has_many: review_content, through:: active_reviews, source:: reviewed
  has_many: reviewed_content, through:: passive_reviews, source:: reviewer

Review model

class Review<ApplicationRecord
  belongs_to: reviewer, class_name: "User"
  belongs_to: reviewed, class_name: "User"
  validates: reviewer_id, presence: true
  validates: reviewed_id, presence: true
  • Answer # 1

    <% if current_user.review_content.include? (@ user)%>

    It was possible.

Related articles