0
我开发了一个应用程序,我似乎遇到了一些与我的关联有关的问题。我有以下几点:将两个变量传递给单独的表...关联问题
class User < ActiveRecord::Base
acts_as_authentic
has_many :questions, :dependent => :destroy
has_many :sites , :dependent => :destroy
end
问题
class Question < ActiveRecord::Base
has_many :sites, :dependent => :destroy
has_many :notes, :through => :sites
belongs_to :user
end
网站(认为这是问题的答案)
class Site < ActiveRecord::Base
acts_as_voteable :vote_counter => true
belongs_to :question
belongs_to :user
has_many :notes, :dependent => :destroy
has_many :likes, :dependent => :destroy
has_attached_file :photo, :styles => { :small => "250x250>" }
validates_presence_of :name, :description
end
当一个站点(答案)创建我成功通过question_id到Sites表,但我无法弄清楚如何传递user_id。这里是我的SitesController#创建
def create
@question = Question.find(params[:question_id])
@site = @question.sites.create!(params[:site])
respond_to do |format|
format.html { redirect_to(@question) }
format.js
end
end
刚刚尝试过,仍然成功传递了question_id而不是user_id。 – bgadoci 2010-05-15 03:15:23
做到了。谢谢。 – bgadoci 2010-05-15 03:28:52