Rails 3: Create an instance with 3 foreign keys.
- by donald
Hello,
Having a reviews table:
# Table name: reviews
#
# id :integer not null, primary key
# wsp_id :integer
# service_id :integer
# user_id :integer
# description :text
# rating :integer
# created_at :datetime
# updated_at :datetime
#
belongs_to :wsp
belongs_to :service
belongs_to :user
How can I create a review for a service and pass the wsp_id and user_id? Do I need to use nested routes?
I am able to do @user.reviews.new(params[:review]) but I'm not being able of passing the wsp_id and the service_id.
Here's my Reviews create controller.
def create
@review = current_user.reviews.new(params[:review])
if @review.save
#Saved
else
#Error, not saved
end
end
What am I doing wrong?
Thank you!