Rails - Associations - Automatically setting an association_id for a model which has 2 belongs_to?

Yes, there is a 'good practice' way involving callbacks class Post before_validation_on_create :set_language protected def set_language self. Language ||= self.user. Language if self.

User end end Then, you can user.posts. Create(:text => "blah") or post. Create(:text => "fewf").

Yes, there is a 'good practice' way involving callbacks. Class Post before_validation_on_create :set_language protected def set_language self. Language ||= self.user.

Language if self. User end end Then, you can @user.posts. Create(:text => "blah") or post.

Create(:text => "fewf").

Excellent thats brilliant. – robodisco Apr 13 '10 at 7:53.

I would just make a create_post function in the user model: def create_post(text) posts. Create(:text => text, :language_id => language_id) end then just call it where ever you need.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions