开发者

I want to able to test for object names in an instance variable of a form

I have an instance variable in a form @partnership.

Depending on how that form is called it has a associated object Landlord or Seller. In the example below it was called by a Seller.

I want to test to see what objects exist in the @partnership instance

ie

 if @partnership.objectname== Seller 
   do something
 elsif parnership.objectname= Landlord
   do somethhing else
 end

Below is debug of the ob开发者_如何学运维ject called by a seller. Can anyone point me in the right direction?

--- !ruby/object:Partnership 
attributes: 
  name: 
  created_at: 
  updated_at: 
  default_partnership: false
attributes_cache: {}

new_record: true
sellers: []


First, it's probably an error when you wrote the code, but you forgot the @ in:

elsif parnership.objectname= Landlord

Second, instead of

@partnership.objectname== Seller

you should use:

@partnership.class == Seller

or

@partnership.is_a? Seller

But I dont see why you want to do that: it's not want you want. A partnership is not a Seller or a Landlord, right? How is defined the association between Partnership and sellers/landlords ? Are you using polymorphism ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜