<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Blocks in Views (Newbie)' | Pragmatic Forums</title>
    <link>https://forums.pragprog.com/forums/22/topics/146</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Blocks in Views (Newbie) posted by Fredrik W @ Fri, 02 May 2008 23:09:32 -0000</title>
      <description>&lt;p&gt;I think you&amp;#8217;re getting the error because you&amp;#8217;re using the &amp;#8220;puts&amp;#8221; method inside of a view template.&lt;/p&gt;


	&lt;p&gt;&amp;lt;% @files.each do |file| %&amp;gt;
  &amp;lt;&lt;span&gt;= &amp;#8216;&lt;li&gt;&amp;#8216;&lt;ins&gt;file&lt;/ins&gt;&amp;#8216;&lt;/li&gt;&amp;#8217; %&amp;gt;&lt;br /&gt;&amp;lt;&lt;/span&gt; end %&amp;gt;&lt;/p&gt;


	&lt;p&gt;should probably work, even if the latter solution proposed by timothy is more elegant.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://railscasts.com/episodes/40"&gt;http://railscasts.com/episodes/40&lt;/a&gt; might interest you as well. It discusses how you can refactor blocks into helper methods that accepts blocks and how to go about with that.&lt;/p&gt;</description>
      <pubDate>Fri, 02 May 2008 23:09:32 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:22:146:2715</guid>
      <author>Fredrik W</author>
      <link>https://forums.pragprog.com/forums/22/topics/146</link>
    </item>
    <item>
      <title>Blocks in Views (Newbie) posted by Timothy Knight @ Sat, 05 Jan 2008 03:56:36 -0000</title>
      <description>&lt;p&gt;Well, if we are talking Rails, why not use the content_tag helper here?  Remember each item needs to be surrounded by an (li) and there is no need for a (br) after each item.  Perhaps there is a one line way of doing this, but doing a block works just fine for me.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;% unless @files.nil? %&amp;gt;
    &amp;lt;h1&amp;gt;Files or Directories 3&amp;lt;/h1&amp;gt;
      &amp;lt;ul&amp;gt;
            &amp;lt;% @files.each do |file| %&amp;gt;
                &amp;lt;%= content_tag :li, file %&amp;gt;
            &amp;lt;% end %&amp;gt;
      &amp;lt;/ul&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Sat, 05 Jan 2008 03:56:36 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:22:146:2118</guid>
      <author>Timothy Knight</author>
      <link>https://forums.pragprog.com/forums/22/topics/146</link>
    </item>
    <item>
      <title>Blocks in Views (Newbie) posted by Don Bessinger @ Sat, 05 Jan 2008 02:10:01 -0000</title>
      <description>&lt;p&gt;I&amp;#8217;m in the same boat you are as far as learning both Ruby and Rails, and I played around with the same things to make nicer formats.  It looks like you&amp;#8217;ve tried to include &lt;span class="caps"&gt;HTML&lt;/span&gt; tags within the &amp;lt;% ... %&amp;gt; brackets.  Ruby expects everything in there to be Ruby code, so try moving the &lt;span class="caps"&gt;HTML&lt;/span&gt; tags out.  Something like this may work:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;lt;% if @files %&amp;gt;
  &amp;lt;h1&amp;gt;Files or Directories 2&amp;lt;/h1&amp;gt;
  &amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;%= @files.each {|file| puts file} %&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;br/&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;

	&lt;p&gt;That&amp;#8217;s untested, but you get the idea &amp;#8211; keep that Ruby and &lt;span class="caps"&gt;HTML&lt;/span&gt; separate.&lt;/p&gt;</description>
      <pubDate>Sat, 05 Jan 2008 02:10:01 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:22:146:2116</guid>
      <author>Don Bessinger</author>
      <link>https://forums.pragprog.com/forums/22/topics/146</link>
    </item>
    <item>
      <title>Blocks in Views (Newbie) posted by Keyton Weissinger @ Tue, 20 Nov 2007 12:51:35 -0000</title>
      <description>&lt;p&gt;OK. So I&amp;#8217;m a noob in both Rails and Ruby&amp;#8212;but I&amp;#8217;m trying to migrate and approach the code from a Ruby perspective.&lt;/p&gt;


	&lt;p&gt;As such, in the Instant Gratification Fun Time section, I tried the following (to do a bit better in the &amp;#8220;looks like Ruby&amp;#8221; category than the example):
    &lt;pre&gt;&amp;lt;% if @files %&amp;gt;
    &amp;lt;h1&amp;gt;Files or Directories 2&amp;lt;/h1&amp;gt;
    &amp;lt;ul&amp;gt;
      &amp;lt;%= @files.each {|file|}%&amp;gt;
    &amp;lt;/ul&amp;gt;
    &amp;lt;% end %&amp;gt;&lt;/pre&gt;&lt;br /&gt;OK. No problem. That works. I get (or similar) in the resulting &lt;span class="caps"&gt;HTML&lt;/span&gt;:&lt;br /&gt;Files or Directories 2&lt;br /&gt;appcomponentsconfigdbdocliblogpublicRakefileREADMEscripttesttmpvendor&lt;/p&gt;


	&lt;p&gt;But if I want to add a little markup:&lt;br /&gt;&lt;pre&gt;    &amp;lt;% if @files %&amp;gt;
    &amp;lt;h1&amp;gt;Files or Directories 2&amp;lt;/h1&amp;gt;
    &amp;lt;ul&amp;gt;
      &amp;lt;%= @files.each {|file| puts '&amp;lt;li&amp;gt;'+file+'&amp;lt;/li&amp;gt;&amp;lt;br/&amp;gt;'}%&amp;gt;
    &amp;lt;/ul&amp;gt;
    &amp;lt;% end %&amp;gt;&lt;/pre&gt;&lt;br /&gt;I get the exact same thing in my resulting &lt;span class="caps"&gt;HTML&lt;/span&gt; page (i.e. no markup):&lt;br /&gt;Files or Directories 2&lt;br /&gt;appcomponentsconfigdbdocliblogpublicRakefileREADMEscripttesttmpvendor&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve tried it in IRb to make sure the Ruby itself acts the way I think it should (and to make sure I wasn&amp;#8217;t making a stupid Ruby mistake). But that worked fine.&lt;/p&gt;


	&lt;p&gt;What up?&lt;/p&gt;


	&lt;p&gt;Thanks in advance.&lt;/p&gt;


	&lt;p&gt;Keyton Weissinger&lt;/p&gt;</description>
      <pubDate>Tue, 20 Nov 2007 12:51:35 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:22:146:1952</guid>
      <author>Keyton Weissinger</author>
      <link>https://forums.pragprog.com/forums/22/topics/146</link>
    </item>
  </channel>
</rss>
