On 22 Feb 2011, at 03:40, Ryan <ryan...@gmail.com> wrote:

> This should probably be easy but for some reason I can't get past a
> simple routine.  I have a model for Companies and for Applications.  A
> company has many applications.  So in this instance I have a company
> id and I want to find all applications associated with that company.
> I tried the following:
> 
> <%= Company.find(1).applications.each { |app| app.name } %> in my
> view.
> 

each returns the collection you iterated over. If you want the return value to 
be the array containing the result of evaluating the block for each object, 
then use map. Alternatively you can do

<% collection.each do |object| %>
  <%= object.name %>
<% end %>

Fred

> This returns "#<Application:0xb6736afc>#<Application:
> 0xb672f1d0>#<Application:0xb672f130>#<Application:
> 0xb672ef50>#<Application:0xb672ed34>#<Application:
> 0xb672e924>#<Application:0xb672e884>" when the view is rendered.
> 
> I'm not really sure what this is, but it does have one entry for each
> of my applications for that company.  So I know it is creating the
> right number of entries just not sure what the output means.
> 
> I'm sure I am doing something monumentally stupid but I can't seem to
> find any examples of this that return this output.  Any help that can
> be provided is very much appreciated.
> 
> Thank you!
> 
> -- 
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to