Я разработал приложение и у меня возникли проблемы с ассоциациями. У меня есть следующее:
class User < ActiveRecord::Base
acts_as_authentic
has_many :questions, :dependent => :destroy
has_many :sites , :dependent => :destroy
end
Вопросы * * 1004
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 # create
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