<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>has_many :developers</title>
    <link rel="alternate" type="text/html" href="http://www.hasmanydevelopers.com/" />
    <link rel="self" type="application/atom+xml" href="http://www.hasmanydevelopers.com/atom.xml" />
    <id>tag:www.hasmanydevelopers.com,2008-06-26://1</id>
    <updated>2008-08-01T18:39:08Z</updated>
    <subtitle>Agile Web development</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Open Source 4.12</generator>

<entry>
    <title>Nightmares with datetime_select and the attr_locked plugin</title>
    <link rel="alternate" type="text/html" href="http://www.hasmanydevelopers.com/2008/08/nightmares-with-datetime-selec.html" />
    <id>tag:www.hasmanydevelopers.com,2008://1.11</id>

    <published>2008-08-01T15:35:51Z</published>
    <updated>2008-08-01T18:39:08Z</updated>

    <summary>Yesterday, a co-worker had some growing pains when updating a Rails 1.2.3 application to Rails 2.1. I gladly came to the rescue (he actually saved me from a boring job) and we analyzed together what was the error we were...</summary>
    <author>
        <name>Román González</name>
        
    </author>
    
        <category term="bugs" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="bugrails21plugin" label="bug rails2.1 plugin" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.hasmanydevelopers.com/">
        <![CDATA[<p>Yesterday, a co-worker had some growing pains when updating a Rails 1.2.3 application to Rails 2.1. I gladly came to the rescue (he actually saved me from a boring job) and we analyzed together what was the error we were getting on the app.</p>
<br/>
The thing happened to be on the form_helper method <pre style="display:inline;">datetime_select</pre>
<br/>
<br/>
<textarea name="code" class="ruby">

<% form_for :mode do |f| -%>
<!-- some html code -->
<%= f.datetime_select :recent_called_at, :order => [:year, :month, :day] %>
<% end -%>

</textarea>
<br/>
<p>A chunk of code (just like the one above) was throwing an exception that said:</p>
<br/>
<pre>ArgumentError: wrong number of arguments (1 for 2)</pre>
<br/>
<br/>
The exception was getting threw inside a method called <pre style="display:inline;">date_or_time_select</pre> that was being invoked; inside the <pre style="display:inline;">datetime_select</pre> method.
<br/>
<br/>
We checked out the plugins that could overwrite this method, and <pre style="display:inline;">attr_locked</pre> was doing it via <pre style="display:inline;">alias_method_chain</pre>. The problem was that, this overwrite didn't provide the correct number of parameters for the Rails 2.1 version (the Rails 2.1 version of <pre style="display:inline;">datetime_select</pre> accepts an extra hash parameter called html_options). We made some little changes to the current implementation and it worked as expected.
<br/>
<br/>
<p>Hope you can get some benefits from this <a href="http://pastie.org/245785.txt">patch</a></p>
]]>
        
    </content>
</entry>

<entry>
    <title>Just a mockup you say?</title>
    <link rel="alternate" type="text/html" href="http://www.hasmanydevelopers.com/2008/07/just-a-mockup-you-say.html" />
    <id>tag:www.hasmanydevelopers.com,2008://1.9</id>

    <published>2008-07-17T14:58:43Z</published>
    <updated>2008-07-17T16:28:47Z</updated>

    <summary> .entry-asset { line-height: 1.5em; } .entry-asset a { text-decoration: none; } .entry-asset dl.pros-cons dt { padding-left: 5px; color: white; } .entry-asset dl.pros-cons dt.pro { background-color: green; } .entry-asset dl.pros-cons dt.con { margin-top: 5px; background-color: red; } Recently, one of...</summary>
    <author>
        <name>Román González</name>
        
    </author>
    
        <category term="programming" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="rubycmstips" label="ruby cms tips" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.hasmanydevelopers.com/">
        <![CDATA[<style> 
.entry-asset {
  line-height: 1.5em;
}
 
.entry-asset a {
  text-decoration: none;
}

.entry-asset dl.pros-cons dt {
  padding-left: 5px;
  color: white;
}

.entry-asset dl.pros-cons dt.pro {
  background-color: green;
}

.entry-asset dl.pros-cons dt.con {
  margin-top: 5px;
  background-color: red;
}
  
</style>
<p>Recently, one of our customers wanted to have a mockup of an application. We thought at first to use Rails to make this mockup, but suddenly we realize that it was overkilling to create models and controllers when the requirements are not clear enough.</p>

<p>Once we decided not to use Rails to do this task, we did study some Ruby <acronym title="Content Management System">CMS</acronym> around the Web. The different options we came around were:</p>

<ul>
  <li>
     <div class="header">
       <h3><a href="http://staticmatic.rubyforge.org">StaticMatic</a></h3>
     </div>
     <dl class="pros-cons">
        <dt class="pro">Pro</dt>
        <dd> 
        It offers a lot of neat features like partials, layouts, host configurations and the most outstanding: <strong>custom view helpers</strong>.
       </dd>
       <dt class="con">Con</dt>
       <dd>
         It just limited to <a href="http://haml.hamptoncatlin.com">Haml &amp; Sass</a> templates, so you will need to know this template system in order to use it.
       </dd>
     </dl>
  </li>
  <li>
     <div class="header">
       <h3><a href="http://nanoc.stoneship.org/">Nanoc</a></h3>
     </div>
     <dl class="pros-cons">
        <dt class="pro">Pro</dt>
        <dd>Is one of the biggest Ruby CMS around on the Web, it offers a lot of features like partials, layouts, templates, filters, tasks, etc.</dd>
        <dt class="con">Con</dt>
        <dd><acronym title="In My Humble Opinion">IMHO</acronym>, is just to <strong>big</strong> for the average mockup site, if you will use this to make a mockup, you probably would like to stick with rails.
        </dd>
      </dl>
  </li>
  <li>
     <div class="header">
       <h3><a href="http://webgen.rubyforge.org/index.html">Webgen</a></h3>
     </div>
     
     <dl class="pros-cons">
        <dt class="pro">Pro</dt>
        <dd>It offers the same options as many other CMS (partials, layouts, filters).</dd>
        <dt class="con">Con</dt>
        <dd>The configuration is not as comfortable as in other CMS.</dd>
     </dl>
  </li>
  <li>
     <div class="header">
       <h3><a href="http://webby.rubyforge.org/">Webby</a></h3>
     </div>
     <dl class="pros-cons">
        <dt class="pro">Pro</dt>
        <dd>It offers the same options as many other CMS (partials, layouts, filters), but also, it provides helpers for rendering <a href="http://www.latex-project.org/">LaTeX</a> and <a href="http://www.graphviz.org/">Graphviz</a> content, 
          offers the chance to make custom rake tasks, offers <a href="http://coderay.rubychan.de/">CodeRay</a> and <a href="http://ultraviolet.rubyforge.org/">Ultraviolet</a> support for code highlighting on the mockup. The configuration is pretty 
          easy, and it offers auto generation on file changes.
        </dd>
        <dt class="con">Con</dt>
        <dd>It does not offer the custom view helpers feature and the docs are not as big as you would like.</dd>
     </dl>
  </li>
</ul>

<p>As you may guess, I went to the option of Webby, it seems the more middle-size CMS made in Ruby that offers a lot of options and is easy to configure.</p> 

<p>If you want to provide more observations on the comments section, is highly appreciated, I did not make a deep study on the others CMS, so maybe I'm missing some pros on each of them.</p>]]>
        
    </content>
</entry>

<entry>
    <title>ActiveScaffold - RJS Error with Firefox 3 and Safari 3.1</title>
    <link rel="alternate" type="text/html" href="http://www.hasmanydevelopers.com/2008/07/activescaffold-rjs-error-with.html" />
    <id>tag:www.hasmanydevelopers.com,2008://1.8</id>

    <published>2008-07-03T20:10:32Z</published>
    <updated>2008-07-03T20:46:51Z</updated>

    <summary>Recently I&apos;m testing in Firefox 3 the &quot;admin&quot; section - implemented using ActiveScaffold - of a Rails application we made. I&apos;m getting RJS Errors when trying to update a record: TypeError: $$(&quot;#admin__operator_details-update-151-form a.cancel&quot;).first().link is undefined $$(&quot;#admin__operator_details-update-151-form a.cancel&quot;).first().link.close_with_refresh(); The issues is...</summary>
    <author>
        <name>Edgar González</name>
        
    </author>
    
        <category term="bugs" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="activescaffold" label="activescaffold" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="firefox" label="firefox" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="javascript" label="javascript" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rails" label="rails" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rjs" label="rjs" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rubyonrails" label="rubyonrails" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="safari" label="safari" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.hasmanydevelopers.com/">
        <![CDATA[<p>Recently I'm testing in Firefox 3 the "admin" section - implemented using <a href="http://activescaffold.com/">ActiveScaffold</a> - of a Rails application we made.</p>

I'm getting RJS Errors when trying to update a record:
<ul>
<li><code>TypeError: $$("#admin__operator_details-update-151-form a.cancel").first().link is undefined</code></li>

<li><code>$$("#admin__operator_details-update-151-form a.cancel").first().link.close_with_refresh();</code></li>
</ul>

<p>The issues is already reported as #<a href="http://code.google.com/p/activescaffold/issues/detail?id=553">553</a></p>

<p>The summary is that the problem lies within the deprecated <code>getElementsByClassName</code> function in the <code>active_scaffold.js</code>.</p>

<p>To fix (thanks to Eric Bjorkvall) just replace in files:

<ul>
<li><code>/public/javascripts/active_scaffold/default/active_scaffold.js</code></li>
<li><code>/vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js</code></li>
</ul>

the line:

<textarea name="code" class="javascript">
this.adapter.getElementsByClassName('cancel').each(function(elem) {
</textarea>

with:

<textarea name="code" class="javascript">
this.adapter.select('.cancel').each(function(elem) { 
</textarea>
</p>

<p>Instead of replacing the original assets of ActiveScaffold I skipped the change on <code>/vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js</code> and just comment the <code>/vendor/plugins/active_scaffold/init.rb</code> in order to avoid the copy assets on plugin initialization.</p>


]]>
        
    </content>
</entry>

<entry>
    <title>View Tips to avoid Growing Pains</title>
    <link rel="alternate" type="text/html" href="http://www.hasmanydevelopers.com/2008/07/view-tips-to-avoid-growing-pai.html" />
    <id>tag:www.hasmanydevelopers.com,2008://1.5</id>

    <published>2008-07-02T23:05:45Z</published>
    <updated>2008-07-03T00:35:57Z</updated>

    <summary>Finally it comes the time when (even if you avoided at all costs) you must develop the view part of the project. Here I&apos;ll summarize some of my experiences in Tips that you should keep in mind before start coding...</summary>
    <author>
        <name>Román González</name>
        
    </author>
    
        <category term="programming" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="tips" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="railsviewtips" label="rails view tips" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://www.hasmanydevelopers.com/">
        <![CDATA[<p>Finally it comes the time when (even if you avoided at all costs) you must develop the view part of the project. Here I'll summarize some of my experiences in Tips that you should keep in mind before start coding like a monkey.</p>

<p><big>Reorganize your view structure if the project doesn't follow the Rails golden path</big></p>

</p>A lot of people tries at all costs to adapt their code to the Rails organization, that shouldn't be always the case.</p>
 
</p>There will be times when you will have a same partial, shared in more than one controller. This normally causes some questions about why the partial is in this controller and not in the other, the simple answer to that question would be: "the partial is in the controller X because it was the first one who used it".</p>

<p>In this cases, you should keep  a shared folder inside the views folder, this way you'll know that the partial doesn't belong to any controller at all, is just a shared view between lot's of controllers. If you notice that your shared folder is starting to get fat, organize partials that have common purposes in sub-folders, this way you won't be lost when looking for a shared partial with a particular purpose.</p>

<p>Then, when rendering a partial, you would do something like</p>

<textarea name="code" class="ruby">render :partial => 'shared/header/month'</textarea>

<p>Here we have shared partials that are being used in the header sections of lot's of controllers. This way you keep an order in your views that is more comfortable and more understandable.</p>

<p><big>In your partials, use helpers as much as you can</big></p>

<p>When you have partials, is probably because you repeat the same view in a lot of places. The thing is that you normally would like the partials to behave differently in some cases, say you want the URL's of the partials of a profile to point somewhere else or not to point anywhere at all (when you have a public profile for example). In this cases the best thing you can do is use helpers for returning the URL's.</p>

<p>You shouldn't bother with lots of if's and else's when the sweet polymorphism can do the job quite easy, just overwrite the method in the controller's helper and the partial will behave differently on each controller it is called<a href="#note1"><sup>1</sup></a>.</p>

<p>So for example, Imagine we have a profile section, and you have 2 versions of this profile, the public version, and the private version. This versions have a lot of things in common in the view side, but when we are in public profile, all the links points to a link of a public section, while when on private profile, the links point to private sections.</p>

<p>The view on the partial (shared/header/month.html.erb) would be something like</p>

<textarea name="code" class="html"><ul id="month-header">
  <li><%= last_month_link(current_month) %></li>
  <li><%= verbose_format_of_month(current_month) %></li>
  <li><%= next_month_link(current_month) %></li>
</ul></textarea>

<p>Now, when we are on the public controller, the helper should behave like</p>

<textarea name="code" class="ruby">module PublicHelper
  def last_month_link(current_month)
    link_to('Last Month', public_profile_path(:month => 1.month.ago(current_month)))
  end

  def next_month_link(current_month)
    link_to('Next Month', public_profile_path(:month => 1.month.from_now(current_month)))
  end
end</textarea>

<p>And on the private controller, the helper should behave like</p>

<textarea name="code" class="ruby">module PublicHelper
  def last_month_link(current_month)
    link_to('Last Month', profile_path(:month => 1.month.ago(current_month)))
  end

  def next_month_link(current_month)
    link_to('Next Month', profile_path(:month => 1.month.from_now(current_month)))
  end
end</textarea>

<p>Here we are letting the polymorphism of the helpers solve the view repetition, by just providing a method that behaves differently depending on where we are standing.</p>

<p><big>Parametrize... <strong>ALWAYS</strong></big></p>

<p>Programmers are lazy, and there is nothing wrong with that, but sometimes this laziness can give us some nasty moments, it all starts with: "why pass it as a parameter? Just access it via the current_user, or the @instance_variable and you won't have to pass parameters every time you invoke this helper/partial".</p>

<p>This will give you more problems than benefits at the end, just imagine what would happen if the helper method/partial would work for every user we would like to, <strong>but</strong> it only calls the current_user?. This is when refactoring comes along and we change the current_user for a parametrized user, the thing is that you call this refactored method like 150 times. There is when you say... "damn, it would be easier if I just passed the user as a parameter from the beginning".  Always keep in mind that the more you use your global environment, the less reusable is your code.</p>

<p>Don't to use instance variables in the partials (change them with the :locals option), nor to use instance variables on the helper modules if they are not being used <strong>only</strong> in the module for private logic (pass the objects as parameters to the functions).</p>

<p>I hope this 3 tips can help you get a better start when coding views.</p>
<br/>
<hr/>
<br/>
<ol id="footnotes">
  <li id="note1">
You have to keep in mind that this probably won't work in recent versions of Rails unless you comment the inclusion of all the helpers in all the views (I wouldn't recommend this feature if you want your views to be scalable).
  </li> 
</ul>]]>
        

    </content>
</entry>

<entry>
    <title>Welcome aboard</title>
    <link rel="alternate" type="text/html" href="http://www.hasmanydevelopers.com/2008/07/welcome-aboard.html" />
    <id>tag:www.hasmanydevelopers.com,2008://1.7</id>

    <published>2008-07-02T22:36:37Z</published>
    <updated>2008-07-03T00:17:51Z</updated>

    <summary>Well, finally a blog. We decided (flip of coin, you know) that having a few paragraphs of static content and call it &quot;the company web site&quot; was so boring, and useless that we were going to completly drop it, and...</summary>
    <author>
        <name>Aníbal Rojas</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-US" xml:base="http://www.hasmanydevelopers.com/">
        <![CDATA[Well, finally a blog. We decided (flip of coin, you know) that having a few paragraphs of static content and call it "the company web site" was so boring, and useless that we were going to completly drop it, and focus in the blog.<br /><br />Anyway, there is "page" called <a href="http://www.hasmanydevelopers.com/everything-you-wanted-to-know.html">Everything you wanted to know before hiring us</a> just in case you have heard about us and you are considering to do so.<br /><br />We are supposed to keep this site updated with great content, so please feel to bookmark it or better add the feed to <br /> ]]>
        
    </content>
</entry>

</feed>
