<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Tag html</title>
    <link>http://www.robbyonrails.com/articles/tag/html</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Flash Message Conductor</title>
      <description>&lt;p&gt;Do you find yourself copying and pasting the same code from Rails application-to-application as new projects start? Our team has a handful of projects in development right now and we notice that some of these &lt;em&gt;reusable&lt;/em&gt; components tend to get out of sync when we bounce between projects. So, we&amp;#8217;re making an effort to spot these and are creating a handful of plugins so that we can keep them updated between projects. (I&amp;#8217;m sure that a lot of you do this as well)&lt;/p&gt;


	&lt;p&gt;In an effort to share some of our patterns, we&amp;#8217;ll try to release them into the wild for others to use and perhaps if you have better patterns to offer, we&amp;#8217;re always interested in improving our approach.&lt;/p&gt;


	&lt;h2&gt;Introducing Flash Message Conductor&lt;/h2&gt;


	&lt;p&gt;Over the years, our designers and developers have approached the management of flash messages several different ways. In Rails, the default way to add something to a flash message is to do something like this in your controller.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;flash&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:message&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;You have successfully signed in to your account.&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;What we began doing a while back is to create a few controller helper methods:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;add_message&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;You have successfully signed in to your account.&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="ident"&gt;add_notice&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;You've Got Mail!&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="ident"&gt;add_error&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;Oops! Something got fucked up!&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Really, nothing too crazy here, just a pattern that our developers have preferred to managing our application&amp;#8217;s flash messages.&lt;/p&gt;


	&lt;p&gt;Okay, so now for the part of the puzzle that we aimed to make consistent across our projects. Rendering flash messages would usually result in several lines of conditionals in our application layout to check if the flash had any values assigned to it. As we worked with our &lt;span class="caps"&gt;HTML&lt;/span&gt;/CSS designers to define a consistent pattern, we moved our code into a helper for rendering flash messages.&lt;/p&gt;


	&lt;p&gt;With Flash Message Conductor, we just need to pop in the following into our application layout.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="punct"&gt;&amp;lt;%=&lt;/span&gt;&lt;span class="string"&gt; render_flash_messages %&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;If we had called &lt;code&gt;add_message&lt;/code&gt;, it&amp;#8217;d render the following:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;div&lt;/span&gt; &lt;span class="attribute"&gt;id&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;flash_messages&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt; &lt;span class="attribute"&gt;class&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;message&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;You have successfully done XYZ...&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;div&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Or, should you have called &lt;code&gt;add_error&lt;/code&gt;, it&amp;#8217;d render the following:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;div&lt;/span&gt; &lt;span class="attribute"&gt;id&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;flash_messages&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt; &lt;span class="attribute"&gt;class&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;error&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;Oops! Something went bonkers!&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;div&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;What we&amp;#8217;ve done here is defined a consistent pattern for our designers and developers to follow. We&amp;#8217;ll always have a &lt;code&gt;div&lt;/code&gt; container that will use a &lt;code&gt;p&lt;/code&gt; tag to display the flash messages with a &lt;span class="caps"&gt;CSS&lt;/span&gt; class value that maps to the type of flash message that we&amp;#8217;re displaying. This makes it easier for us to reuse the same flash message styling (and tweak if necessary), but we know that it&amp;#8217;ll produce the same &lt;span class="caps"&gt;HTML&lt;/span&gt; across our applications.&lt;/p&gt;


	&lt;h3&gt;Installing Flash Message Conductor&lt;/h3&gt;


	&lt;p&gt;Like most &lt;em&gt;modern&lt;/em&gt; Rails applications, you can install with:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
script/plugin install git://github.com/planetargon/flash-message-conductor.git
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Then all of our helper methods will be available to your application. We&amp;#8217;ve also included an example &lt;span class="caps"&gt;CSS&lt;/span&gt; file, which you&amp;#8217;ll find in the plugin directory.&lt;/p&gt;


	&lt;p&gt;Sample output:&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/wuef/flash-message-area"&gt;&lt;img src="http://img.skitch.com/20080830-n8k8ikkk3i8himuxhk7pbf8tg3.preview.jpg" alt="flash message area" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080"&gt;Uploaded with &lt;a href="http://plasq.com/"&gt;plasq&lt;/a&gt;&amp;#8217;s &lt;a href="http://skitch.com"&gt;Skitch&lt;/a&gt;!&lt;/span&gt;&lt;/div&gt;

	&lt;p&gt;Anyhow, we&amp;#8217;ve posted the plugin up on GitHub for you all to use, if you&amp;#8217;d like to adopt a similar approach. If you have any alternative patterns that has helped your team, do share and I&amp;#8217;m looking forward to sharing some more of ours in the near future.&lt;/p&gt;


	&lt;p&gt;For more information, visit the &lt;a href="http://github.com/planetargon/flash-message-conductor"&gt;Flash Message Conductor plugin&lt;/a&gt; on GitHub.&lt;/p&gt;


	&lt;p&gt;If anything, hopefully this will inspire those of you who find yourself copying/pasting artifacts from application-to-application to extract that code into it&amp;#8217;s own reusable plugin. :-)&lt;/p&gt;
</description>
      <pubDate>Fri, 29 Aug 2008 16:35:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:95e800a7-f1a5-429b-94be-aed635f73036</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/08/29/flash-message-conductor</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>patterns</category>
      <category>pattern</category>
      <category>rubyonrails</category>
      <category>rails</category>
      <category>development</category>
      <category>html</category>
      <category>css</category>
      <category>team</category>
      <category>planetargon</category>
    </item>
    <item>
      <title>Tip: Link to Unimplemented</title>
      <description>&lt;p&gt;Throughout our design and development process, we&amp;#8217;re working around areas of the site that are not yet implemented but we also want to be able to allow our clients to demo their application. In an effort to manage their expectations, we need to be careful about what we link to. If a page/widget isn&amp;#8217;t ready to be demo&amp;#8217;d yet, we should avoid providing pathways to get interact with or navigate there. However, when we&amp;#8217;re implementing &lt;span class="caps"&gt;HTML&lt;/span&gt;/CSS for pages, it&amp;#8217;s sometimes makes sense to not hide certain things on the screen.&lt;/p&gt;


	&lt;p&gt;For example, let&amp;#8217;s suppose that you&amp;#8217;re working on the primary navigation of an application. You know what the other sections are going to be, but you&amp;#8217;ve only implemented a few of them so far. Your &lt;span class="caps"&gt;HTML&lt;/span&gt;/CSS person is working on the design for the navigation and wants to have them be proper links&amp;#8230; even to pages that don&amp;#8217;t yet exist.&lt;/p&gt;


	&lt;p&gt;One option, which is quite common, is to provide a link with &lt;code&gt;href="#"&lt;/code&gt;. This works to some extent, but when people click on things, they naturally expect something to happen in response.&lt;/p&gt;


	&lt;p&gt;This approach doesn&amp;#8217;t mesh well with our team as we don&amp;#8217;t really want to field any questions like, &amp;#8220;the navigation links are all broken. Nothing happens!&amp;#8221;&lt;/p&gt;


	&lt;p&gt;So, a pattern that we&amp;#8217;ve been using for a while is to trigger a javascript alert for every link within an implemented area that is linking to something that isn&amp;#8217;t yet implemented.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s take a really basic javascript function like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
# public/javascripts/application.js
function unimplemented() {
  alert("NOTICE\n\nThis feature is not implemented yet. Please check back again soon!");
}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This allows us to do the following:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;a href="javascript:unimplemented();"&amp;gt;link text&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;When someone clicks the link, they&amp;#8217;ll see a typical javascript alert message. This informs our clients/beta testers that we&amp;#8217;re paying attention to what works and what doesn&amp;#8217;t.&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/ecx1/unimplemented"&gt;&lt;img src="http://img.skitch.com/20080327-pbcddnkj85bu6m9x7mspme5y6.preview.jpg" alt="unimplemented" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080"&gt;Uploaded with &lt;a href="http://plasq.com/"&gt;plasq&lt;/a&gt;&amp;#8217;s &lt;a href="http://skitch.com"&gt;Skitch&lt;/a&gt;!&lt;/span&gt;&lt;/div&gt;

	&lt;p&gt;Let&amp;#8217;s take it a step further and push this into a view helper.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
# app/helpers/application_helper.rb
def link_to_unimplemented( link_text, *args )
  link_to_function( link_text, 'unimplemented()', *args)
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, we&amp;#8217;re able to use &lt;code&gt;link_to_unimplemented&lt;/code&gt; and pass any arguments that you&amp;#8217;d pass to the default &lt;code&gt;link_to&lt;/code&gt; view helper.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;%= link_to_unimplemented( 'link text', { :class =&amp;gt; 'link_class_name' } ) -%&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now our web designers can go about their work and use this helper as necessary.&lt;/p&gt;


	&lt;p&gt;An nice benefit for doing this is that we have a pattern that we follow so that we can rely upon to make sure that we don&amp;#8217;t forget anything. This is the equivalent of adding @TODO@s throughout our code base.&lt;/p&gt;


	&lt;p&gt;If we search through &lt;code&gt;app/views&lt;/code&gt; for &amp;#8216;&lt;strong&gt;&lt;code&gt;link_to_unimplemented&lt;/code&gt;&lt;/strong&gt;&amp;#8217; we should be able to prevent missing any broken links. In the next screenshot, I&amp;#8217;m using &lt;code&gt;grep&lt;/code&gt; with colorized matches.&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/ecxh/unimplemented-2"&gt;&lt;img src="http://img.skitch.com/20080327-eg83hqhgpspk4n71hquswjpasf.preview.jpg" alt="unimplemented 2" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080"&gt;Uploaded with &lt;a href="http://plasq.com/"&gt;plasq&lt;/a&gt;&amp;#8217;s &lt;a href="http://skitch.com"&gt;Skitch&lt;/a&gt;!&lt;/span&gt;&lt;/div&gt; 

	&lt;p&gt;As you can see, we have something left to implement in that area of the application. :-)&lt;/p&gt;


	&lt;p&gt;This has been one of those lightweight patterns that we&amp;#8217;ve been able to adopt and it&amp;#8217;s definitely helped manage the expectations of our clients throughout our development process.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;d love to hear your thoughts on this. How does your team handle things like this?&lt;/p&gt;


	&lt;h2&gt;Related Posts&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.robbyonrails.com/articles/2007/08/01/designers-developers-and-the-x_-factor"&gt;Designers, Developers, and the x_ Factor&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.robbyonrails.com/articles/2007/10/06/spice-up-your-terminal-with-colored-grep-pattern-results"&gt;Spice up your Terminal with colored grep pattern results&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
</description>
      <pubDate>Thu, 27 Mar 2008 06:10:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f2aad3fb-9728-4db3-8504-a7bf2bd76b24</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/03/27/tip-link-to-unimplemented</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>clients</category>
      <category>javascript</category>
      <category>helper</category>
      <category>development</category>
      <category>design</category>
      <category>html</category>
      <category>tip</category>
    </item>
    <item>
      <title>Managing SEO-friendly HTML Titles with Rails</title>
      <description>&lt;p&gt;I&amp;#8217;ve seen this come up a few times in the #rubyonrails &lt;span class="caps"&gt;IRC&lt;/span&gt; channel and figured that I&amp;#8217;d post a quick entry for future reference.&lt;/p&gt;


	&lt;h2&gt;Problem: &lt;span class="caps"&gt;HTML&lt;/span&gt; titles&lt;/h2&gt;


	&lt;p&gt;&lt;strong&gt;You want to have a clean way to manage the titles on your &lt;span class="caps"&gt;HTML&lt;/span&gt; pages.&lt;/strong&gt;&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
      &amp;lt;title&amp;gt;Robby on Rails &amp;amp;mdash; Article Title Goes Here&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
      ...
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Possible Solution(s):&lt;/p&gt;


	&lt;p&gt;Since the &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; tag is usually declared in your layout, you need to be able to dynamically update this information from almost every action in your application.&lt;/p&gt;


	&lt;p&gt;Here are a few ways that I&amp;#8217;ve seen this handled.&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Use a instance variable, which would have a default value and you could override it in any controller action&lt;/li&gt;
		&lt;li&gt;Use the &lt;code&gt;content_for&lt;/code&gt; method to manage it.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Let&amp;#8217;s take a few minutes to look at these two approaches.&lt;/p&gt;


	&lt;h3&gt;Instance Variable&lt;/h3&gt;


	&lt;p&gt;With the instance variable, you might end up with something like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  # app/views/layouts/application.html.erb
  &amp;lt;title&amp;gt;Robby on Rails &amp;amp;mdash; &amp;lt;%= @html_title || 'Default text here...' -%&amp;gt;&amp;lt;/title&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Then in a controller action&amp;#8230;&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  # app/controllers/articles_controller.rb
  def show
    # ...
    @html_title = @article.title
  end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So, that&amp;#8217;s one way to handle it and is probably a more common way.&lt;/p&gt;


	&lt;h3&gt;The &lt;code&gt;content_for&lt;/code&gt; helper method approach&lt;/h3&gt;


	&lt;p&gt;This solution is very similar (and underneath uses an instance variable).&lt;/p&gt;


	&lt;p&gt;We&amp;#8217;ll use the &lt;a href="http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001069"&gt;content_for&lt;/a&gt; and a little &lt;code&gt;yield&lt;/code&gt; action.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  # app/views/layouts/application.html.erb
  &amp;lt;title&amp;gt;Robby on Rails &amp;lt;%= (html_title = yield :html_title) ? html_title : '&amp;amp;mdash; Default text here...' %&amp;gt;&amp;lt;/title&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Then we&amp;#8217;ll create a helper method.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  # app/helpers/application_helper.rb
  def set_html_title(str="")
    unless str.blank?
      content_for :html_title do
       "&amp;amp;mdash; #{str} " 
      end
    end
  end  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, instead of defining the &lt;span class="caps"&gt;HTML&lt;/span&gt; &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; value in the controllers, we&amp;#8217;ll just toss this into our html.erb files as necessary.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;% set_html_title(@article.name) -%&amp;gt;
  ... rest of view
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;..and that&amp;#8217;s pretty much it.&lt;/p&gt;


	&lt;h3&gt;Which is the better solution?&lt;/h3&gt;


	&lt;p&gt;This is where we&amp;#8217;ll not find a lot of consensus amongst people. I&amp;#8217;m a fan of the &lt;code&gt;content_for&lt;/code&gt;-based approach and defining the title in views rather than in controller actions. I&amp;#8217;m an advocate of skinny controllers and while I&amp;#8217;m not a big fan of messy views, I believe that there is less overhead in managing this within the View-world.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;d love to hear your thoughts on this. Perhaps you have a more eloquent for managing things like this? Do share. :-)&lt;/p&gt;
</description>
      <pubDate>Wed, 26 Mar 2008 16:41:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:de684f82-efe6-48b6-a6f5-68ea542d72ef</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/03/26/managing-seo-friendly-html-titles-with-rails</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>html</category>
      <category>rails</category>
      <category>rubyonrails</category>
      <category>helpers</category>
    </item>
    <item>
      <title>That Checkbox Needs a Label</title>
      <description>&lt;p&gt;As a user of many web applications, I often find myself noticing little things that slow me down. One such thing is the use of checkboxes in web forms. It&amp;#8217;s not the problem of checkboxes itself, it&amp;#8217;s the face that checkboxes require the user to really focus their attention to a fairly small box on the page and perform a click inside. If you&amp;#8217;re filling out a form really quickly, it&amp;#8217;s almost guaranteed that you&amp;#8217;ll take advantage of you your tab key to get through each field quickly. Sometimes there are &lt;code&gt;select&lt;/code&gt; boxes, which require the user to make selections with their mouse. Checkboxes drive me crazy because it requires more time to position the cursor and move on.&lt;/p&gt;


	&lt;p&gt;So, when I see a form like this, I don&amp;#8217;t see it being very quick to interact with.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/missing_label-20071201-222047.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;While I&amp;#8217;m not in love with the date selection interface here, my bigger pain has been the checkbox in the form. Why? Because they forgot to use the &lt;code&gt;&amp;lt;label for=""&amp;gt;&lt;/code&gt; HTML tag.&lt;/p&gt;


	&lt;p&gt;What&amp;#8217;s the problem? Well, I don&amp;#8217;t have the convenience of clicking on the label text, which would toggle the corresponding checkbox.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/missing_label-20071201-222751.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;I know, many of you know all about this&amp;#8230; but I run into this problem everywhere. This is an accessibility issue for people and really just increases the chances for a frustrating user experience. When you use the label tag properly&amp;#8230; it will provide a larger amount of the screen for people to click, which reduces the chance of not clicking in the right spot. The label tag was designed with this in mind so that people could click &lt;em&gt;close enough&lt;/em&gt; to trigger the desired action.&lt;/p&gt;


	&lt;p&gt;Here is an example of where it becomes really useful.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/good_label_for_usage-20071201-224846.jpg" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;So, the lesson? Please remember to use the label for tag. :-)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;input type="checkbox" id="remember_me" name="remember_me" value="true" /&amp;gt;
&amp;lt;label for="remember_me"&amp;gt;Remember info?&amp;lt;/label&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This is an easy thing to forget when building web applications. We&amp;#8217;ve forgot and I&amp;#8217;m sure you have too. I just wanted to point it out though because I see this happen so much&amp;#8230; even in new sites.&lt;/p&gt;


	&lt;p&gt;Perhaps you run into similar problems with web applications that can be fixed with just a little more &lt;span class="caps"&gt;HTML&lt;/span&gt;. Care to share your experiences?&lt;/p&gt;


	&lt;p&gt;For more information, read &lt;a href="http://diveintoaccessibility.org/day_28_labeling_form_elements.html"&gt;Labeling form elements&lt;/a&gt;  from the &lt;a href="http://diveintoaccessibility.org/"&gt;Dive Into Accessibility&lt;/a&gt; site.&lt;/p&gt;
</description>
      <pubDate>Sun, 02 Dec 2007 00:43:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:efe7de1c-ff24-41f9-9ef0-4cdb23f20523</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/12/02/that-checkbox-needs-a-label</link>
      <category>Programming</category>
      <category>html</category>
      <category>forms</category>
      <category>checkboxes</category>
      <category>interaction</category>
      <category>design</category>
      <category>web</category>
      <category>applications</category>
      <category>usability</category>
      <category>IxD</category>
      <category>accessibility</category>
    </item>
    <item>
      <title>Spec Your Views</title>
      <description>&lt;p&gt;I meant to work on this post&amp;#8230; oh about 7 months ago.&lt;/p&gt;


	&lt;p&gt;Way back in January (7 months ago), Jamis Buck posted an article titled, &lt;a href="http://weblog.jamisbuck.org/2007/1/29/testing-your-views"&gt;Testing your views&lt;/a&gt;, which gave a few tips on using Test::Unit to, as the title suggests, test your views.&lt;/p&gt;


	&lt;p&gt;While, I&amp;#8217;m not going to rewrite everything that Jamis wrote, I&amp;#8217;d like to show you how to test these views with RSpec. (you might take a moment to quickly read his post&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;In this example, I&amp;#8217;m going to show you how we&amp;#8217;re able to write specs for the following &lt;span class="caps"&gt;RHTML&lt;/span&gt;, which  you&amp;#8217;ll notice matches the code that he wrote tests for.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;% if @user.administrator? %&amp;gt;
    Hi &amp;lt;%= @user.name %&amp;gt;! You appear to be an administrator.
    &amp;lt;%= link_to "Click here", admin_url, :id =&amp;gt; "admin_link" %&amp;gt;
    to see the admin stuff!
  &amp;lt;% end %&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Jamis writes, &lt;em&gt;&amp;#8220;The only really significant thing you ought to be testing here is that the admin link only shows up for administrators. &amp;#8220;&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;So, let&amp;#8217;s do just that, but with RSpec.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not sure how Jamis is handling his view tests, but we&amp;#8217;re going to approach our view specs, much like we approach our controller specs, with the use of mocks and stubs, because we really don&amp;#8217;t need to spec any of our models at this level in the application.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Write specifications for your models&amp;#8230; in your model specs &lt;strong&gt;not&lt;/strong&gt; in your controller or view specs.&lt;/p&gt;


	&lt;p&gt;The first thing that we&amp;#8217;re going to do is setup a custom spec helper, because for something like an mocked user, will probably get reused in other areas of the user interface. Spec helpers are essentially modules that you can include in your RSpec descriptions (the block that starts with &lt;code&gt;describe&lt;/code&gt;) and reuse.&lt;/p&gt;


	&lt;p&gt;In this spec helper, I&amp;#8217;m going to include two methods, to mock the User model and stub out any of the methods that are necessary for spec&amp;#8217;n this view.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
module MockUserHelper
  def mock_normal_user
    user = mock(User)
    user.stub!(:administrator?).and_return(false)   # &amp;lt;--- NOT an admin
    user.stub!(:name).and_return('David Chelimsky')
    return user
  end

  def mock_admin_user
    user = mock(User)
    user.stub!(:administrator?).and_return(true)    # &amp;lt;--- IS an admin
    user.stub!(:name).and_return('Aslak Hellesoy')
    return user
  end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;In the &lt;code&gt;mock_normal_user&lt;/code&gt; method, we&amp;#8217;re constructing a mock object and stubbing out the methods that we see are being called in the &lt;span class="caps"&gt;RHTML&lt;/span&gt; code. In &lt;code&gt;mock_admin_user&lt;/code&gt;, we&amp;#8217;re basically doing the same thing, but just stubbing the &lt;code&gt;administrator?&lt;/code&gt; method to return &lt;code&gt;true&lt;/code&gt; for this mock user.&lt;/p&gt;


	&lt;p&gt;By stubbing these methods, we&amp;#8217;ll be able to send a non-ActiveRecord object to the view and have it render without knowing the difference. For example, the &lt;code&gt;if @user.administrator?&lt;/code&gt; condition will return true or false, depending on how we stubbed it.&lt;/p&gt;


	&lt;p&gt;For more information on mocks and stubs, &lt;a href="http://rspec.rubyforge.org/documentation/mocks/index.html"&gt;read here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Now that we have our spec helper, let&amp;#8217;s go ahead and dive into a few specifications for the view.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
describe "index page" do
  include MockUserHelper

  it "should render an admin link for an admin user" do
    assigns[:user] = mock_admin_user
    render 'index'
    response.should have_tag('a#admin_link')
  end

  it "should not render an admin link for a normal, non-admin user" do
    assigns[:user] = mock_normal_user
    render 'index'
    response.should_not have_tag('a#admin_link')
  end
end  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;strong&gt;Please note:&lt;/strong&gt; This code example is only longer than the one shown by Jamis because he didn&amp;#8217;t include how he setup all his user sessions/objects. ;-)&lt;/p&gt;


	&lt;p&gt;When these specs are run, we can see the following results.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://myskitch.com/robbyrussell/rspec_results-20070801-233809.jpg" alt="" /&gt;&lt;br /&gt;&lt;small&gt;Pretty output courtesy of RSpec + TextMate bundle&lt;/small&gt;&lt;/p&gt;


	&lt;p&gt;Great, we&amp;#8217;ve been able to write specifications for our Rails views without a lot of pain. Stay tuned for more posts on this topic as I continue writing about how Designers and Developers can work together, in harmony. (&lt;a href="http://www.robbyonrails.com/articles/2007/08/01/designers-developers-and-the-x_-factor"&gt;see my last post on this topic&lt;/a&gt;)&lt;/p&gt;


	&lt;p&gt;For more information on adopting RSpec, please visit the &lt;a href="http://rspec.rubyforge.org"&gt;RSpec project homepage&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Thu, 02 Aug 2007 02:00:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c21e25cf-1a4a-4b9f-a628-89fc00945829</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2007/08/02/spec-your-views</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>rails</category>
      <category>rubyonrails</category>
      <category>testing</category>
      <category>driven</category>
      <category>bdd</category>
      <category>rspec</category>
      <category>behavior</category>
      <category>mocks</category>
      <category>designers</category>
      <category>rhtml</category>
      <category>html</category>
      <category>specs</category>
    </item>
  </channel>
</rss>
