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

  • Home
  • SEARCH
  • 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 526637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:47:52+00:00 2026-05-13T08:47:52+00:00

I have an object called Review which :belongs_to two objects: Users and Vendors. In

  • 0

I have an object called Review which :belongs_to two objects: Users and Vendors. In other words, there is always a vendor writing a review for a specific vendor.

When I create a review, I tried to use the .build method to presumably add the foreign_key at the time the new record is created for review.vendor_id and review.user_id.

When I put into the controller for review the build statement for user id without one for capturing the vendor id, it works like a charm. When I add the vendor_id the user_id stays ‘nil’.

Help? Reviews is a nested resource: vendors/3/reviews/new

Forms for review/new:

<% form_for [@vendor, @review] do |f| %>

In the review controller:

    def new
      @vendor = Vendor.find(params[:vendor_id])
      @review = @vendor.reviews.build
      #@review = Review.new
    end



def create
    @vendor = Vendor.find(params[:vendor_id])
    @review = @current_analyst.reviews.build params[:review]

    if @review.save
      flash[:notice] = "Successfully created review."
      redirect_to review_path(@review)
    else
  render :action => 'new'
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-13T08:47:52+00:00Added an answer on May 13, 2026 at 8:47 am

    This is your problem.

    @review = @current_analyst.reviews.build 
    @vendor = Vendor.find(params[:vendor_id])  
    @review = @vendor.reviews.build params[:review]
    

    You are overwriting @review with a new Review generated by @vendor.reviews.build. Instead of creating a new Review, you should just set the second foreign key using the methods created by the belongs_to association. Like this:

    @review = @current_analyst.reviews.build params[:review]
    @review.vendor_id = params[:vendor_id]
    

    To speed this process up, you can make :vendor_id part of the form_for @review. Assuming a Review is a nested resource of Vendor

    Example:

    Controller Actions:

    def new 
      @vendor = Vendor.find(params[:vendor_id])
      @review = @vendor.reviews.build
    end
    
    def create
      @review = @current_analyst.reviews.build params[:review]
      if @review.save
        redirect_to @review
      else
        render :action => :new
      end
    end
    

    Form partial:

    <% form_for @review do |f| %>
      ...
        Standard form information
      ...
      <%= f.hidden_field :vendor_id%>
      <%= submit_tag %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unlike IDENTITY types, applications have no way of determining the… May 13, 2026 at 8:48 am
  • Editorial Team
    Editorial Team added an answer Alternative solution: It is possible (but very tricky) to use… May 13, 2026 at 8:48 am
  • Editorial Team
    Editorial Team added an answer EDIT: Added IFNULL to return 0 as count_checked when outer… May 13, 2026 at 8:48 am

Related Questions

I'm getting blocked on a jsp page and our 1 java engineer isn't able
We have an email confirmation page for registration which can be hit with a
I have a functional test suite failing in a Rails 2.2.2 application. The exception
Maybe a simple question but I really don't know what to do. When I
I have an object called Settings that inherits from NSMutableDictionary . When I try

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.