Message from discussion
model issues with ruby on rails 3
Received: by 10.50.47.201 with SMTP id f9mr5481133ign.5.1334260570421;
Thu, 12 Apr 2012 12:56:10 -0700 (PDT)
X-BeenThere: rubyonrails-talk@googlegroups.com
Received: by 10.50.56.204 with SMTP id c12ls9995162igq.2.canary; Thu, 12 Apr
2012 12:55:28 -0700 (PDT)
Received: by 10.42.197.137 with SMTP id ek9mr2558368icb.5.1334260528136;
Thu, 12 Apr 2012 12:55:28 -0700 (PDT)
Received: by 10.42.197.137 with SMTP id ek9mr2558367icb.5.1334260528127;
Thu, 12 Apr 2012 12:55:28 -0700 (PDT)
Return-Path: <clan...@googlemail.com>
Received: from mail-ob0-f179.google.com (mail-ob0-f179.google.com [209.85.214.179])
by gmr-mx.google.com with ESMTPS id ar8si2672529igc.2.2012.04.12.12.55.28
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 12 Apr 2012 12:55:28 -0700 (PDT)
Received-SPF: pass (google.com: domain of clan...@googlemail.com designates 209.85.214.179 as permitted sender) client-ip=209.85.214.179;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of clan...@googlemail.com designates 209.85.214.179 as permitted sender) smtp.mail=clan...@googlemail.com; dkim=pass header...@googlemail.com
Received: by mail-ob0-f179.google.com with SMTP id ef5so3963179obb.24
for <rubyonrails-talk@googlegroups.com>; Thu, 12 Apr 2012 12:55:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20120113;
h=mime-version:in-reply-to:references:from:date:message-id:subject:to
:content-type:content-transfer-encoding;
bh=a9Ucg5Bj2WQoSHR5HNFXgFxi+xZpxeIk5diF0VlIV3E=;
b=cTkbwRUeg70dhi0sb00hur1ycx9WEz5qa+8XwS4GWVkuqlhu/8oU83YZCABOi1RSc5
uCx/5XsbDdDl68V6IdyShYRE1550MVpijlUfBTYwmY/mM2fsxJb5J5xTq8FppMQ5VBEh
ECIrK7DPWNyeSfcdJ1SWusMjO+mkhy7jmtKdB0pPTtjPliZ21moBsodJ3dL1kXw4zyiE
cyCnzrrF54+bmwrmTUA9Jb8ZP5dttNGwTxz2coCzplKgs863d6k82IlnvAW1qsZLt8AD
D/p9P+NIyeL2ODcl3MjJUkTtUR7sLcrcaSEtcKOU3LF/6NMkjAIwH++rKVyA9TIVaTEf
9/5g==
Received: by 10.182.89.39 with SMTP id bl7mr4651030obb.65.1334260527954; Thu,
12 Apr 2012 12:55:27 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.182.165.105 with HTTP; Thu, 12 Apr 2012 12:54:57 -0700 (PDT)
In-Reply-To: <10510821.144.1334244464626.JavaMail.geo-discussion-forums@pbtd9>
References: <25448280.112.1334242172462.JavaMail.geo-discussion-forums@pbtd9>
<CAL=0gLvo0EFC153c1keLsXG7+cP=4prnNo7AyZ0k7kCtovH...@mail.gmail.com> <10510821.144.1334244464626.JavaMail.geo-discussion-forums@pbtd9>
From: Colin Law <clan...@googlemail.com>
Date: Thu, 12 Apr 2012 20:54:57 +0100
Message-ID: <CAL=0gLvjgA-E4=8aAhAFU9EVmnZQcFc6pQ9wkdaVp80ggG7...@mail.gmail.com>
Subject: Re: [Rails] model issues with ruby on rails 3
To: rubyonrails-talk@googlegroups.com
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On 12 April 2012 16:27, amvis <vgrkrish...@gmail.com> wrote:
>
>
> On Thursday, 12 April 2012 10:54:35 UTC-4, Colin Law wrote:>
>>
>> > =C2=A0=C2=A0=C2=A0 @user =3D User.find_by_user_name(user_name)
>> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if !...@user.business_admins.nil?
>> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 put=
s "Am here"
>> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 @business=
_admin =3D @user.business_admins[0]
>> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 end
>> > class User < ActiveRecord::Base
>> > =C2=A0 has_many :business_admins
>> > end
>> >
>> > class BusinessAdmin < ActiveRecord::Base
>> > =C2=A0 belongs_to :user
>> > end
>> >
>> > Here what i am trying, I am using Mozilla rest-client, basically here
>> > the
>> > user_name found in the User table, But i didn't put that id in the
>> > BusinessAdmin, So what the problem is=C2=A0 when i run the code, this =
if
>> > !...@user.business_admins.nil? will return true, because am getting this
>> > "Am
>> > here"
>>
>> >I am not sure what you are saying. =C2=A0If you have user has_many
>> >business_admins then @user.business_admins will never be nil. =C2=A0It =
may
>> >be an empty array however. =C2=A0Perhaps you should be testing for the
>> >array empty rather than nil.
>
>>Colin
>
> Basically, the BusinessAdmin doesn't have that=C2=A0 use_name's id, then =
why this
> checking happned?
First what relationships have you got between the models (has_many,
belongs_to or whatever)?
As I said last time, if user has_many business_admins then
@user.business_admins will always (effectively) be an array, which may
be empty. It will never be nil.
By the way, you sent your last email to me instead of to the list.
Please make sure you reply to the list.
Colin
>
> if !...@user.business_admins.nil?
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
puts "Am here"
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 @busin=
ess_admin =3D @user.business_admins[0]
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 end
>
>
> Thank you
> vishnu
>