creating a model form inside another model, how to pass 'this'?

17 views
Skip to first unread message

S Ahmed

unread,
May 8, 2014, 11:03:44 AM5/8/14
to rubyonra...@googlegroups.com
I am inside a model, and need to create another model, how to I pass 'this' as a parameter?


Example:


class User < AR
  has_one :company
  def create_associations!
    @company = Company.build_with_user(this)
  end
end


So I'm trying to create the company association using a method from the Company model, and pass it a User parameter.

How do I pass 'this' in ruby?

S Ahmed

unread,
May 8, 2014, 2:34:58 PM5/8/14
to rubyonra...@googlegroups.com
self :)

Colin Law

unread,
May 8, 2014, 3:55:45 PM5/8/14
to rubyonra...@googlegroups.com
On 8 May 2014 16:03, S Ahmed <sahme...@gmail.com> wrote:
> I am inside a model, and need to create another model, how to I pass 'this'
> as a parameter?
>
>
> Example:
>
>
> class User < AR
> has_one :company
> def create_associations!
> @company = Company.build_with_user(this)

use self.build_company instead. See
http://guides.rubyonrails.org/association_basics.html#has-one-association-reference

Colin
Reply all
Reply to author
Forward
0 new messages