<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Ruby on Rails Notes &#187; views</title> <atom:link href="http://railsnotes.com/tag/views/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Javascript in Haml</title><link>http://railsnotes.com/474-javascript-haml/</link> <comments>http://railsnotes.com/474-javascript-haml/#comments</comments> <pubDate>Thu, 07 May 2009 00:43:20 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[haml]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=474</guid> <description><![CDATA[One thing that is not obvious with HAML is how to add javascript. In the past, haml didn't really like javascript that much but the latest version of haml on github makes it very simple. It's done using the :javascript filter and this post shows you how with an example.]]></description> <content:encoded><![CDATA[<p></p><p>One thing that is not obvious with HAML is how to add javascript. In the past, <a
href="http://b.lesseverything.com/2008/2/19/haml-doesn-t-like-javascript" target="_blank">haml didn&#8217;t really like javascript that much</a> but the latest version of haml on github makes it very simple. It&#8217;s done using the :javascript filter. Here&#8217;s an example:</p><pre>:javascript
  jQuery(function(){
    tog("#forgot_password_clicker", "#login_form");
    tog("#forgot_password_clicker", "#forgot_form", forgot_text);
  });</pre><p>You can also mix in ruby variables by using the standard way of interpolating ruby with strings through: #{ }. Here&#8217;s an example of how it all works in a full page with a ruby variable mixed in:</p><pre>!!! XML
!!!
%html{:xmlns =&gt; "http://www.w3.org/1999/xhtml", "xml:lang" =&gt; "en", :lang =&gt; "en"}
  %head
    %meta{'http-equiv' =&gt; "content-type", :content =&gt; "text/html;charset=UTF-8"}

  %body
    - @some_ruby_variable = "something goes here."
    :javascript
      #{@some_ruby_variable}
      jQuery(function(){
        tog("#forgot_password_clicker", "#login_form");
        tog("#forgot_password_clicker", "#forgot_form", forgot_text);
      });</pre><p>This makes this HTML:</p><pre>&lt;?xml version='1.0' encoding='utf-8' ?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'&gt;
  &lt;head&gt;
    &lt;meta content='text/html;charset=UTF-8' http-equiv='content-type' /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;script type='text/javascript'&gt;
      //&lt;![CDATA[
        something goes here.
        jQuery(function(){
          tog("#forgot_password_clicker", "#login_form");
          tog("#forgot_password_clicker", "#forgot_form", forgot_text);
        });
      //]]&gt;
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>]]></content:encoded> <wfw:commentRss>http://railsnotes.com/474-javascript-haml/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Response to &quot;Thoughts on Haml&quot;</title><link>http://railsnotes.com/395-response-to-thoughts-on-haml/</link> <comments>http://railsnotes.com/395-response-to-thoughts-on-haml/#comments</comments> <pubDate>Sat, 02 May 2009 01:32:53 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[haml]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=395</guid> <description><![CDATA[James Britt recently wrote about his experience with HAML, the alternative to ERB. His basic position was that HAML for noobies and he doesn't get why or how HAML makes real world code better. In this post, I show with code why HAML is awesome and how it kicks ERb-butt.]]></description> <content:encoded><![CDATA[<p></p><p><em>James Britt wrote up a <a
href="http://www.jamesbritt.com/2009/4/29/thoughts-on-haml" target="_blank">blog post talking about his experience with HAML</a></em><em>, the alternative to ERB. His basic position (from what I gathered) was that it&#8217;s for noobies and that no one has explained to him why or how HAML makes real world code better&#8230; either than saying &#8220;wait, it&#8217;ll start looking beautiful soon enough and you won&#8217;t go back.&#8221;  This is my detailed, somewhat-reasoned response.</em></p><p>I like HAML because it&#8217;s clean and easy to read. Cleaner &amp; easier to read than ERb&#8230; and yes, I&#8217;ll back that up with code:</p><p><a
href="http://pastie.org/private/n8ipfrkxlremo4jwtxiww">http://pastie.org/private/n8ipfrkxlremo4jwtxiww</a></p><p>Converting the ERB file to HAML took less than 4 minutes, mostly hitting the delete key.</p><p>A 39 line code becomes 31 lines&#8230; and that&#8217;s not even the big win. Now if  you don&#8217;t think the HAML code chuck is visually easier to digest than the ERB version, that&#8217;s fine. Stay with ERB.</p><p>I find HAML code is easier to maintain &amp; write&#8230; and it has nothing to do with a lack of knowledge of html or anything else.</p><h2>How is it easier to write and maintain?</h2><p>First, there is the overt clarity when it comes to sass (css) &amp; haml code.</p><pre>## haml file
.container
  .header
    %h1 Site Name
    %ul
      %li= link_to ...
      %li= link_to ...
      %li= link_to ...
  .content
    stuff
  .footer</pre><pre>## sass (css) file for this

.container
  background-color: black

  .header
    background-color: white

    h1
      font-family: Funky
      font-size: 3em
    ul
      li
        a:link, a:visited
        a:hover
  .content
  .footer</pre><p>Do you see the pairing? I <strong>LOVE</strong> that! I find it clean &amp; easy to read.</p><p>Secondly, it&#8217;s very ruby like.</p><p>This:</p><pre>&lt;% if @subscription.state == 'trial' %&gt;
  &lt;label&gt;Trial expiration date:&lt;/label&gt;
  &lt;%= @subscription.next_renewal_at.to_s(:long_day) %&gt;

&lt;% else %&gt;
  &lt;% if @subscription.amount &gt; 0 %&gt;
    &lt;label&gt;Next charge date:&lt;/label&gt;
    &lt;%= @subscription.next_renewal_at.to_s(:long_day) %&gt;
    &lt;br/&gt;
    &lt;label&gt;Next charge amount:&lt;/label&gt;
    &lt;%= number_to_currency @subscription.amount %&gt;
    &lt;br/&gt;
    &lt;label&gt;Current payment method:&lt;/label&gt;
    &lt;%= @subscription.paypal? ? 'PayPal' : "#{@subscription.card_number} / #{@subscription.card_expiration}" %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;</pre><p>becomes:</p><pre>- if @subscription.state == 'trial'
  %label Trial expiration date:
  = @subscription.next_renewal_at.to_s(:long_day)

- else
  - if @subscription.amount &gt; 0
    %label Next charge date:
    = @subscription.next_renewal_at.to_s(:long_day)
    %br/
    %label Next charge amount:
    = number_to_currency @subscription.amount
    %br/
    %label Current payment method:
    = @subscription.paypal? ? 'PayPal' : "#{@subscription.card_number} / #{@subscription.card_expiration}"</pre><p>Which looks &amp; feels more like ruby? For me, the choice is clearly the second one. It literally removes anything that doesn&#8217;t communicate what the code should do.</p><p>Anyway, to each his own.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/395-response-to-thoughts-on-haml/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Triggering jQuery code/functions from RJS</title><link>http://railsnotes.com/289-triggering-jquery-code-functions-from-rjs/</link> <comments>http://railsnotes.com/289-triggering-jquery-code-functions-from-rjs/#comments</comments> <pubDate>Sat, 25 Apr 2009 02:32:25 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[rjs]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=289</guid> <description><![CDATA[jQuery is an alternative to Prototype, which is the default javascript library inside Rails. Since RJS generates javascript based on prototype, you might think you can't use jQuery in it.  Although it's technically true, you can still use jQuery by using the page.call feature of RJS.]]></description> <content:encoded><![CDATA[<p></p><p>jQuery is an alternative to Prototype, which is the default javascript library inside Rails. Since RJS generates javascript based on prototype, you might think you can&#8217;t use jQuery in it.  Although it&#8217;s technically true, you can still use jQuery by using the page.call feature of RJS. Here&#8217;s an example:</p><p>## test.js</p><pre>$(function(){
  ...
};

function do_something_amazing {
  ... some slick jQuery code ...
};</pre><p>## something.rjs called using link_to_remote or form_for_remote:</p><pre>page.call 'do_something_amazing'</pre><h3>Gotcha</h3><p>A simple gotcha is if you include &#8220;function be_amazing {&#8230;};&#8221; inside the &#8220;$(function(){&#8230;};&#8221;  you&#8217;ll get an undefined error.</p><p>Credits: I came across this approach while helping shipstar in the #rubyonrails IRC channel</p><p><strong>UPDATE:</strong> Using RJS isn&#8217;t the best approach if you value unobtrusiveness. Here&#8217;s a copy/paste of some reasons why &#8220;RJS is evil&#8221;.</p><blockquote><p>dfr|work: it&#8217;s directly coupled to your dom but isn&#8217;t in it.<br
/> dfr|work: i mean, what&#8217;s rjs? it&#8217;s just a callback thing. Just specify it when you&#8217;re making ajax request.<br
/> dfr|work: and if you need the data from server, specify it via json. It&#8217;s clean and simple.</p></blockquote><p>Expect a follow-up to this explaining how to do this the right way.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/289-triggering-jquery-code-functions-from-rjs/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to link to an anchor</title><link>http://railsnotes.com/275-how-to-link-to-an-anchor/</link> <comments>http://railsnotes.com/275-how-to-link-to-an-anchor/#comments</comments> <pubDate>Thu, 23 Apr 2009 06:05:55 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[anchor]]></category> <category><![CDATA[helpers]]></category> <category><![CDATA[link_to]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=275</guid> <description><![CDATA[If you need to link to a particular part of your website, link anchors are what you need. And linking to link anchors is really simple in Rails. Here&#8217;s an example: &#60;%= link_to "Google Analytics", features_path(:anchor =&#62; "analytics") %&#62; This will output: &#60;a href="/features_path#analytics"&#62;Google Analytics&#60;/a&#62; Here&#8217;s another example: &#60;%= link_to "San Francisco Offices", :controller =&#62; [...]]]></description> <content:encoded><![CDATA[<p></p><p>If you need to link to a particular part of your website, link anchors are what you need. And linking to link anchors is really simple in Rails. Here&#8217;s an example:</p><pre>&lt;%= link_to "Google Analytics", features_path(:anchor =&gt; "analytics") %&gt;</pre><p>This will output:</p><pre>&lt;a href="/features_path#analytics"&gt;Google Analytics&lt;/a&gt;</pre><p>Here&#8217;s another example:</p><pre>&lt;%= link_to "San Francisco Offices", :controller =&gt; 'locations',
                                     :action =&gt; 'index',
                                     :anchor =&gt; 'sf' %&gt;</pre><p>As you&#8217;ve probably noticed, the key part is <strong>:anchor =&gt; &#8216;analytics&#8217;</strong></p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/275-how-to-link-to-an-anchor/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ul CSS trick</title><link>http://railsnotes.com/88-ul-css-trick/</link> <comments>http://railsnotes.com/88-ul-css-trick/#comments</comments> <pubDate>Tue, 10 Feb 2009 22:29:07 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[views]]></category> <category><![CDATA[css]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=88</guid> <description><![CDATA[I had a problem. I had an image that I had floating to the left. Right next to it, I had content. Here&#8217;s what the code looked like: 1 &#60;img style="float:left" src="cover.gif" alt="" /&#62; 2 blah blah blah blah blah blah blah 3 &#60;ul&#62; 4 &#60;li&#62;Item 1&#60;/li&#62; 5 &#60;li&#62;Item 2&#60;/li&#62; 6 &#60;li&#62;Item 3&#60;/li&#62; 7 &#60;/ul&#62; [...]]]></description> <content:encoded><![CDATA[<p></p><p>I had a problem. I had an image that I had floating to the left. Right next to it, I had content. Here&#8217;s what the code looked like:</p><pre><span class='linenum'>    1</span> <span class="text text_plain"><span class="meta meta_paragraph meta_paragraph_text">&lt;img style="float:left" src="cover.gif" alt="" /&gt;
<span class='linenum'>    2</span> blah blah blah blah blah blah blah
<span class='linenum'>    3</span> &lt;ul&gt;
</span><span class='linenum'>    4</span>   <span class="meta meta_paragraph meta_paragraph_text">&lt;li&gt;Item 1&lt;/li&gt;
<span class='linenum'>    5</span>   &lt;li&gt;Item 2&lt;/li&gt;
<span class='linenum'>    6</span>   &lt;li&gt;Item 3&lt;/li&gt;
<span class='linenum'>    7</span> &lt;/ul&gt;</span></span></pre><p>Simple enough, right? It should just work, right? Wrong!</p><p>When viewed in a browser, the above code will screw up your list. What do I mean by &#8220;screw up&#8221; the list? Here&#8217;s a  screenshot to demonstrate:</p><p><img
class="alignnone size-full wp-image-89" src="http://railsnotes.files.wordpress.com/2009/02/floating-image-w_-ul-problem.jpg" alt="floating-image-w_-ul-problem" width="304" height="356" /></p><p>Notice, the bullet points will actually overlap with the image. Ugly! I tried adding margins, padding and a bunch of diff things to both the image and the ul element. Nothing fixed it!</p><p>I started hunting on Google and I ran into this page: <a
href="http://www.webmasterworld.com/css/3697078.htm" target="_blank">http://www.webmasterworld.com/css/3697078.htm</a></p><p>The fix? Add &#8220;overflow: auto;&#8221; to the ul style. Simple! I love it!</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/88-ul-css-trick/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Splitting HAML code into multiple lines</title><link>http://railsnotes.com/73-splitting-haml-code-into-multiple-lines/</link> <comments>http://railsnotes.com/73-splitting-haml-code-into-multiple-lines/#comments</comments> <pubDate>Fri, 23 Jan 2009 19:15:59 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[views]]></category> <category><![CDATA[haml]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=73</guid> <description><![CDATA[If you&#8217;re using HAML and have a really long piece of code, you probably want to split it into multiple lines so it looks clean. Here&#8217;s how you do it. Let&#8217;s say you have this code: %h1.logo= real_account? &#38;&#38; current_account.name ? current_account.name : AppConfig['app_name'] But you&#8217;d rather have: %h1.logo= real_account? &#38;&#38; current_account.name ?  current_account.name : AppConfig['app_name'] [...]]]></description> <content:encoded><![CDATA[<p></p><p>If you&#8217;re using HAML and have a really long piece of code, you probably want to split it into multiple lines so it looks clean. Here&#8217;s how you do it.</p><p><strong>Let&#8217;s say you have this code:</strong></p><pre>%h1.logo= real_account? &amp;&amp; current_account.name ? current_account.name : AppConfig['app_name']</pre><p><strong>But you&#8217;d rather have:</strong></p><pre>%h1.logo= real_account? &amp;&amp; current_account.name ? 
          current_account.name : AppConfig['app_name']</pre><p><strong>All you need is to pipe them using |, like this:</strong></p><pre>%h1.logo= real_account? &amp;&amp; current_account.name ? |
          current_account.name : AppConfig['app_name'] |</pre><p><span
style="color:red">Notice how the last line also has a |. That is required.</span></p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/73-splitting-haml-code-into-multiple-lines/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Commenting Out ERb code in Rails (*.html.erb)</title><link>http://railsnotes.com/34-commenting-out-erb-code-in-rails-htmlerb/</link> <comments>http://railsnotes.com/34-commenting-out-erb-code-in-rails-htmlerb/#comments</comments> <pubDate>Wed, 01 Oct 2008 07:05:27 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[views]]></category> <category><![CDATA[ERb]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=34</guid> <description><![CDATA[Q. Is there an easy way to comment multiple line of ruby in an html.erb file when you have: ... &#60;% .. %&#62; blah &#60;% .. %&#62; blah &#60;% .. %&#62; blah ... I tried to put &#60;!&#8211; &#8211;&#62; around it but its still interpreted. A. There are a few ways. First, you could add [...]]]></description> <content:encoded><![CDATA[<p></p><p><strong>Q.</strong> Is there an easy way to comment multiple line of ruby in an html.erb file when you have:</p><pre>...
&lt;% .. %&gt; blah &lt;% .. %&gt;
blah
&lt;% .. %&gt; blah
...</pre><p>I tried to put &lt;!&#8211; &#8211;&gt; around it but its still interpreted.</p><p>A. There are a few ways. First, you could add a -# at the beginning of the erb tags like this:</p><pre>&lt;%-# whatever erb code -%&gt;</pre><p>Secondly, you could  do an if false statement as explain here <a
href="http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails/">http://blog.localkinegrinds.com/2008/05/02/erb-block-comments-in-rhtml-templates-using-ruby-on-rails</a> like this:</p><pre>&lt;% if false %&gt;&lt;!-- start erb comment --&gt;
...
&lt;% .. %&gt; blah &lt;% .. %&gt;
blah
&lt;% .. %&gt; blah
...
&lt;!-- end erb comment --&gt;&lt;% end %&gt;</pre><p>This will color code that portion as a comment in text editors and will prevent it from getting send to the browsers at all.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/34-commenting-out-erb-code-in-rails-htmlerb/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Ajax File or Image Uploading inside Ruby on Rails</title><link>http://railsnotes.com/19-ajax-file-or-image-uploading-inside-ruby-on-rails/</link> <comments>http://railsnotes.com/19-ajax-file-or-image-uploading-inside-ruby-on-rails/#comments</comments> <pubDate>Tue, 30 Sep 2008 21:48:23 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[ajax]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=19</guid> <description><![CDATA[http://github.com/melvinram/ajax-image-upload/ While adding course covers to my BrainBank app, I put together a simple ruby on rails app that uses attachment_fu and responds_to_parent to upload an image. It should be useful if you&#8217;re thinking of added image uploading to your app. CREDITS http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/ #rubyonrails help on observe_field by wmoxam]]></description> <content:encoded><![CDATA[<p></p><p><a
href="http://github.com/melvinram/ajax-image-upload/"><img
class="alignright" src="http://albumshaper.sourceforge.net/images/Reveal_1.2/newIcon.png" alt="" width="162" height="162" />http://github.com/melvinram/ajax-image-upload/</a></p><p>While adding course covers to my BrainBank app, I put together a simple ruby on rails app that uses attachment_fu and responds_to_parent to upload an image. It should be useful if you&#8217;re thinking of added image uploading to your app.</p><p><strong>CREDITS</strong></p><ul><li><a
href="http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent">http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent</a></li><li><a
href="http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/">http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/</a></li><li>#rubyonrails help on observe_field by <a
href="http://www.workingwithrails.com/person/5751-wesley-moxam"><span
class="Apple-style-span" style="font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;font-family:Arial;color:#000000">wmoxam</span></a></li></ul> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/19-ajax-file-or-image-uploading-inside-ruby-on-rails/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/16 queries in 0.079 seconds using disk

Served from: railsnotes.com @ 2010-09-10 06:05:44 -->