Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4273276
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:41:27+00:00 2026-05-21T07:41:27+00:00

Hi I’m a super beginner and working on my first app, I have a

  • 0

Hi I’m a super beginner and working on my first app, I have a table of venues and users can add reviews to the venues. I would like to be able to hide the review form to users once they have submitted a review, to stop them from submitting more.

This is what I have now:

add review form on venue show page

<% if reviewed? %>
    <%= form_for [@venue, @review], :class => 'rating_ballot' do |f| %>
      <%= f.label("value_1", content_tag(:span, '1'), {:class=>"rating", :id=>"1"}) %>
      <%= radio_button_tag("review[rating]", 1, :class => 'rating_button') %>

      <%= f.label("value_2", content_tag(:span, '2'), {:class=>"rating", :id=>"2"}) %>
      <%= radio_button_tag("review[rating]", 2, :class => 'rating_button') %>

      <%= f.label("value_3", content_tag(:span, '3'), {:class=>"rating", :id=>"3"}) %>
      <%= radio_button_tag("review[rating]", 3, :class => 'rating_button') %>

      <%= f.label("value_4", content_tag(:span, '4'), {:class=>"rating", :id=>"4"}) %>
      <%= radio_button_tag("review[rating]", 4, :class => 'rating_button') %>

      <%= f.label("value_5", content_tag(:span, '5'), {:class=>"rating", :id=>"5"}) %>
      <%= radio_button_tag("review[rating]", 5, :class => 'rating_button') %> <br>

      <p>title: <br>
      <%= f.text_field :title %></p><br>

      <%= submit_tag %>
    <% end %>
  <% end %>

application controller

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
  helper_method :reviewed?

  protected

  def reviewed?
    true
  end

   private

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
end

I cant figure out what the reviewed? helper should be to allow me to do this, any help is greatly appreciated!

edit

I’ve added the has_reviewed helper to the application controller, it now shows this error:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

Extracted source (around line #79):

76:     <%= render :partial => 'reviews/review', :collection => @venue.reviews %>
77:   </div>
78: 
79:   <% if reviewed? %>

application controller

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
  helper_method :current_user
  helper_method :has_reviewed
  helper_method :reviewed?

  protected

  def reviewed?
    Review.has_reviewed(@current_user.id, venue.id)
  end

  def has_reviewed
    !Review.where(:user_id=>user,:venue_id=>venue).blank?
  end

   private

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
end

another edit

I’ve changed the reviewed? helper method to:

  def reviewed?
    if current_user
      Review.has_reviewed(@current_user.id, @venue.id)
    else
      nil
    end
  end

but it gives undefined method `has_reviewed’ for # error

schema

A venue has many reviews

A user has many reviews

A review belongs to a user and a venue

the routes looks like this:

App::Application.routes.draw do

  resources :sessions
  resources :users
  resources :venues do
    resources :reviews
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:41:28+00:00Added an answer on May 21, 2026 at 7:41 am

    Presuming you make the change as suggested by Wes, the reviewed? method would look in the database to see if this user has made a review.

    The reviews table will need to have a column for the user that made the review and the venue it reviewed.

    So the code would look something like this…

    EDITED to reflect schema recently added

    In the controller

    def reviewed?
      if current_user
        @current_user.has_reviewed(@venue.id)
      else
        nil
      end
    end
    

    In the User model…

    class User < ...
      has_many :reviews
    
      def has_reviewed(venueid)
        reviews.exists?(:venue_id => venueid)
      end
    
      ...
    end
    

    Basically I think the has_reviewed is better off in the User model as the user has_many reviews, and then it can check if the user has reviewed the given venue.
    I am presuming that the Model Review has a foreign key to venue called venue_id, as a Review belongs_to a Venue and that would be the standard thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.