@user = User.find_by_user_name(user_name)
if !@user.business_admins.nil?
puts "Am here"
@business_admin = @user.business_admins[0]
end
class User < ActiveRecord::Base
has_many :business_admins
end

class BusinessAdmin < ActiveRecord::Base
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 when i run the code, this *if
!@user.business_admins.nil?* will return *true*, because am getting this *"Am
here"

*Have any issues with this model??...*
*
Thankyou
Vishnu*

*

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Wh5IbFmxT-0J.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Apr 12, 2012 at 2:57 pm

    On 12 April 2012 15:49, amvis wrote:
    @user = User.find_by_user_name(user_name)
    if !@user.business_admins.nil?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end
    class User < ActiveRecord::Base
    has_many :business_admins
    end

    class BusinessAdmin < ActiveRecord::Base
    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  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. If you have user has_many
    business_admins then @user.business_admins will never be nil. It may
    be an empty array however. Perhaps you should be testing for the
    array empty rather than nil.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Apr 12, 2012 at 7:55 pm

    On 12 April 2012 16:27, amvis wrote:

    On Thursday, 12 April 2012 10:54:35 UTC-4, Colin Law wrote:>
    @user = User.find_by_user_name(user_name)
    if !@user.business_admins.nil?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end
    class User < ActiveRecord::Base
    has_many :business_admins
    end

    class BusinessAdmin < ActiveRecord::Base
    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  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.  If you have user has_many
    business_admins then @user.business_admins will never be nil.  It may
    be an empty array however.  Perhaps you should be testing for the
    array empty rather than nil.
    Colin
    Basically, the BusinessAdmin doesn't have that  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?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end


    Thank you
    vishnu
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Amvis at Apr 13, 2012 at 5:50 am

    On Thursday, 12 April 2012 15:54:57 UTC-4, Colin Law wrote:

    On Thursday, 12 April 2012 10:54:35 UTC-4, Colin Law wrote:>
    @user = User.find_by_user_name(user_name)
    if !@user.business_admins.nil?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end
    class User < ActiveRecord::Base
    has_many :business_admins
    end

    class BusinessAdmin < ActiveRecord::Base
    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 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. If you have user has_many
    business_admins then @user.business_admins will never be nil. It may
    be an empty array however. Perhaps you should be testing for the
    array empty rather than nil.
    Colin
    Basically, the BusinessAdmin doesn't have that use_name's id, then why this
    checking happned?
    First what relationships have you got between the models (has_many,
    belongs_to or whatever)?
    when i check like this i got the solution
    *if !@user.business_admins[0]*.nil?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end



    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?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end


    Thank you
    vishnu
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HrrBCKUKJE4J.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Apr 13, 2012 at 8:06 am

    On 13 April 2012 06:50, amvis wrote:
    [snip]
    when i check like this i got the solution

    if !@user.business_admins[0].nil?
    if !@user.business_admins.empty?
    might be a bit cleaner and easier to understand, or
    if @user.business_admins.count == 0

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Amvis at Apr 13, 2012 at 5:54 am

    On Thursday, 12 April 2012 15:54:57 UTC-4, Colin Law wrote:

    On Thursday, 12 April 2012 10:54:35 UTC-4, Colin Law wrote:>

    @user = User.find_by_user_name(user_name)
    if !@user.business_admins.nil?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end
    class User < ActiveRecord::Base
    has_many :business_admins
    end

    class BusinessAdmin < ActiveRecord::Base
    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 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. If you have user has_many
    business_admins then @user.business_admins will never be nil. It may
    be an empty array however. Perhaps you should be testing for the
    array empty rather than nil.
    Colin

    Basically, the BusinessAdmin doesn't have that 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.
    * if !@user.business_admins[0].nil?*
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end


    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?
    puts "Am here"
    @business_admin = @user.business_admins[0]
    end
    Thank you
    vishnu
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/lJCBIYqbByoJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 12, '12 at 2:49p
activeApr 13, '12 at 8:06a
posts6
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Amvis: 3 posts Colin Law: 3 posts

People

Translate

site design / logo © 2022 Grokbase