views:

84

answers:

3

Can any one please help to how to fetch the values of attributes from the has_many Relationship on rails

For example company is one relation and has many email

company --> email

i need to fetch email_address from those company.email

How can i do that?

company.email.email_address
+3  A: 

@company = Company.find(1) @company.emails.collect(&:email_address)

philipth
+1  A: 

Try this

@company = Email_address.find(:all,params[:email_id], :include => #:user, :conditions => "email_id=#{params[:email_id].to_i} AND published=true")

Kuya
+1  A: 
email_addresses = Company.all.map(&:emails).map(&:email_addresses)
ez