ruby on rails - Passing two variables to separate table...associations problem -


I have developed an application and I think there are some problems with my organizations. I have the following:

  class user & lt; ActiveRecord :: Base acts_s_modified has_many: Question ,: Dependent = & gt; : Has_many is deleted: sites ,: depend => : End End  

Question

  Class Question & lt; ActiveRecord :: Base has has_many: sites ,: depend => : Is deleted_maya: notes, via = & gt; : Sites related_to: user end  

sites (think of answering this question)

  class site & lt; ActiveRecord :: Base works_s_viewable: vote_counter = & gt; True_relation: the question is_to: user has_many: notes, dependent => : Has_many is destroyed: likes ,: depend => : Has_attached_file deleted: photos, styles = & gt; {: Small = & gt; "250x250"> } Validates_presence_of: name,: description end  

When a site (answer) is created, I'm successfully passing the question table from Sitemap, but I do not know that user_id How to pass. Here is my site controller #

  def create @question = Question.find (params [: question_id]) @site = @ question.sites.create! (Param [: site]) response_to do | Format | Format.html {redirect_to (@question)} format.js Ends  

D thinks this will work

  @question = current_user.questions.find params [: question_id]  

If not, simply assign to manual .

  @site = @ question.sites.build (params [: site]) @ site.user = current_user @ site.save  

Comments