On Nov 11, 12:26 am, mars <[email protected]> wrote:
> institution.rb
> class Institution < ActiveRecord::Base
>   has_one :alerts
>
>   def find_alerts(institution_id)
>      Alert.find_all(institution_id)
>   end
> end

orthogonal to this, but your associations are borked - that should be

has_many :alerts


and then you can do away with that find  method and do
@institution.alerts
> from irb i tried:
> a = Alert.find_all(1)
> it showed me the correct record
> but if i tried: a.name

that dies because your find_all method returns an array and arrays
don't have a name method.
Your view doesn't display the name because you've put attr_accessor in
your model: Active Record creates accessor functions for you, by using
attr_accessor you've overridden those with versions that don't look at
the values Active Record fetches from the database.

Fred



> it complained: NoMethodError: undefined method 'name', but i already
> defined attr_accessor :name, :value in alert.rb, how come it still
> complained?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to