Hi,
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