A
A
Alexander Isaev2016-04-23 02:04:48
Ruby on Rails
Alexander Isaev, 2016-04-23 02:04:48

How to add records to two tables?

Hello everyone) In general, the situation is this, there is a User and Student table. Student has a user_id. I want to make it so that when saving a record in User , the id of the just saved user appears in the user_id field in the Student table. Tried to do with callbacks, but something doesn't work. Has anyone implemented something similar? Share your experience. Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Talipov, 2016-04-28
@ClickF1

Show me how you implemented it with callbacks.
Do you get

class User
  has_one/has_many :students 
end

Show callback'i please. Why the Student model, if it is needed only for the role?
https://github.com/elabs/pundit
https://github.com/RolifyCommunity/rolify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question