On 12 April 2012 15:49, amvis <[email protected]> wrote: > > @user = User.find_by_user_name(user_name) > if [email protected]_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 > [email protected]_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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

