Topic: find_by_field

i am having a problem find things other than by id.

i am going to the rails c
and this is what i am doing

Profile.all
Profile Load (29.5ms)  SELECT "Profiles".* FROM "Profiles" 
 => [#<Profiles id: 1, name: "Moises", phone: "9545557890", email: "9545554566", Fax: "9544441111", cell: "9545551234", address: "", address2: nil, city: "Margte", state: "Fl", zip: "33308", account_id: 1, created_at: "2012-06-08 19:17:13", updated_at: "2012-06-08 19:17:13">, #<Profiles id: 2,  phone: "99", email: "a@aol.com", Fax: "8", cell: "8", address: "4", address2: nil, city: "5", state: "76", zip: "7", account_id: 10, created_at: "2012-06-09 06:32:09", updated_at: "2012-06-09 06:32:09">] 

now i want to be able to find this profile by the account

but find_by_account_id(10) does not work

Re: find_by_field

Profile.where("account_id = ?" ,10)

now i have to do this in the controller

Re: find_by_field

i was able to get the info that i needed on me controller but now on the views i am having problem displaying the data

When i do

@profile.all i see all the data 

    [#<Profile id: 2,  phone: "99", email: "a@aol.com", Fax: "8", cell: "8", address: "4", address2: nil, city: "5", state: "76", zip: "7", account_id: 10, created_at: "2012-06-09 06:32:09", updated_at: "2012-06-09 06:32:09">]

but when i do

@profile.phone

i get a error that reads

NoMethodError in Profiles#index
undefined method `phone' for #<ActiveRecord::Relation:0x007fedf04974e8>

Re: find_by_field

It means that either you don't have a column/method named 'phone' in your Profile model, either phone is not 'white-listed' via 'attr_accessible' method in the model:

class Profile < AR
  attr_accessible :phone
...
end

Sorry I've just seen the 'phone' in your code. Check 'attr_accessible'.

Last edited by Javix (2012-06-11 11:02:13)

Re: find_by_field

Thanks for your help.
i just checked my model and all the fields are in the attr_accessible

and i dependently have it in the table because when i do @profile.all i see it

any other ideas what could be the problem?