Okay, thanks a lot.  That really helps.  For the logged_in_user, that
would be a User instance method, right?  Something like:

Class User < ActiveRecord::Base
  def return_instructions_array
     instructions = Instructions.return_array(self.appointments)
  end
end

This would be an Instructions class method...is this better than an
Instruction instance method?  like:

Instructions.new.return_array(self.appointments)

I'm never really sure which is better.



On Jun 3, 12:21 am, Colin Law <[email protected]> wrote:
> 2009/6/3 David <[email protected]>:
>
>
>
>
>
> > It seems like there may be a rails method for the following situation:
> > model User
> > has_many :appointments
>
> > model Appointment
> > has_one :instruction
> > belongs_to :user
>
> > model Instruction
> > belongs_to :appointment
>
> > I would like to do User.Appointments.Instruction and return an array
> > with instruction objects but no go.  I am doing the following and
> > wondering if there is a cleaner way?
>
> > appointments = logged_in_user.appointments
> >     �...@instructions = Array.new
> >      appointments.each do |appointment|
> >       �[email protected](appointment.instruction)
> >      end
>
> Something like
> @instructions = logged_in_user.appointments.collect { |a| [a.instruction] }
>
> Though I think I would consider something like putting this in a
> method of User that returned an array of instructions for that user.
> Or a class method or User that does it for the current logged in user.
>  Dependent on the rest of your requirements of course.  You might want
> to consider a class member of Appointments that takes an array of
> appointments and returns an array of instructions.
>
> Colin
>
> Colin
>
>
>
> > Thanks for any help/input.
--~--~---------~--~----~------------~-------~--~----~
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