Philip Hallstrom wrote:
>> In the view code, say it is
>> 
>> <%  @stories.each do |s| %>
>> <%=   "<div>#{h s.inspect}</div>" %>
>> <%  end %>

Another option, although probably not necessary in this case, is to move 
the code into a view helper.

<%= h story_list(@stories) %>

def story_list(stories)
  list = ""
  stories.each do |s|
    list += content_tag(:div, h(s.inspect))
  end
  list
end

Yes, in this case the helper is more verbose (maybe there's a better way 
that what I did), but at least your view code is clean and pretty. The 
ugliness get move outside the view into the helper.

Another common pattern for a case like you show is to move the code that 
actually lists the stories into a partial. Then rendering the partial 
from your view becomes one line:

<%= render :partial => @stories %>
-- 
Posted via http://www.ruby-forum.com/.

-- 
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