1 Replies - 1522 Views - Last Post: 22 July 2016 - 08:12 AM Rate Topic: -----

#1 gerome0123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-July 16

controller passing a data to another model?

Posted 16 July 2016 - 07:07 AM

i have three models student, subject and student_subjects for my join table this three model have an assosiation for student has_many :students and has_many :subjects through student_subjects and this is opposite for my subjects model and the last one is student_subjects belongs to subject and student. now my question is there possible to throw a data to another table im in the student controller and i want to pass a data to my student_subjects table
Is This A Good Question/Topic? 0
  • +

Replies To: controller passing a data to another model?

#2 sidk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-July 16

Re: controller passing a data to another model?

Posted 22 July 2016 - 08:12 AM

View Postgerome0123, on 16 July 2016 - 07:07 AM, said:

i have three models student, subject and student_subjects for my join table this three model have an assosiation for student has_many :students and has_many :subjects through student_subjects and this is opposite for my subjects model and the last one is student_subjects belongs to subject and student. now my question is there possible to throw a data to another table im in the student controller and i want to pass a data to my student_subjects table



Hey there, you can do this. It's just a matter of either invoking the `StudentSubject.create(...)` class directly or using the association helpers that ActiveRecord provides (@student.student_subjects.create(...))

I wrote a post on a related topic a while back which might be helpful to you: http://ducktypelabs....the-join-table/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1