Using Active Record find

Hello everybody…

I’m just getting started with Rails and am stuck. I have two tables, a
user table and a web table.

User < ActiveRecord::Base
has_many :groups

Group < ActiveRecord::Base
belongs_to :user

I’m trying do do a look up to see if a particular user is already part
of a group. The code I have works but it seems there should be an esier
way to do it.

if Group.find(:first, :conditions => {:user_id =>
User.find_by_email(params[:email]), :web_id => session[:web_id]})

Thanks for any help

  • Mark

User < ActiveRecord::Base
has_many :groups

Group < ActiveRecord::Base
belongs_to :user

I’m trying do do a look up to see if a particular user is already part
of a group.

Use the user has_many groups association to check if a user has any
groups.

user = User.find_by_email(email)
user.groups.blank?

Aaron