<?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>Blog Patrick Espake &#187; helper</title>
	<atom:link href="http://blog.patrickespake.com/tag/helper/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.patrickespake.com</link>
	<description>O conhecimento evolui quando é compartilhado!</description>
	<lastBuildDate>Fri, 03 Sep 2010 04:24:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Ruby on Rails plugin stylesheet_by_browser</title>
		<link>http://blog.patrickespake.com/2009/08/03/ruby-on-rails-plugin-stylesheet_by_browser/</link>
		<comments>http://blog.patrickespake.com/2009/08/03/ruby-on-rails-plugin-stylesheet_by_browser/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 01:34:31 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[:ie]]></category>
		<category><![CDATA[all]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[código]]></category>
		<category><![CDATA[código fonte]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[desinstalação]]></category>
		<category><![CDATA[específico]]></category>
		<category><![CDATA[estilo]]></category>
		<category><![CDATA[exemplo]]></category>
		<category><![CDATA[exemplos]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[folha de estilo]]></category>
		<category><![CDATA[fonte]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[instalação]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[navegador]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[plugin install]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[stylesheet_by_browser]]></category>

		<guid isPermaLink="false">http://blog.patrickespake.com/?p=924</guid>
		<description><![CDATA[stylesheet_by_browser Ruby on Rails helper insere o stylesheet de acordo com o navegador. Desta forma você pode adicionar o css específico para cada navegador, na sua folha de estilo, não necessitando mais fazer hacks em uma única folha de estilo css. Instalação Etapa 1 ./script/plugin install git://github.com/patrickespake/stylesheet_by_browser.git Etapa 2 Em seguida, instalar os arquivos necessários [...]]]></description>
			<content:encoded><![CDATA[<p><strong>stylesheet_by_browser</strong></p>
<p>Ruby on Rails helper insere o stylesheet de acordo com o navegador.<br />
Desta forma você pode adicionar o css específico para cada navegador, na sua folha de estilo, não necessitando mais fazer hacks em uma única folha de estilo css.</p>
<p><strong>Instalação</strong></p>
<p><strong>Etapa 1</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>patrickespake<span style="color: #000000; font-weight: bold;">/</span>stylesheet_by_browser.git</pre></div></div>

<p><strong>Etapa 2</strong></p>
<p>Em seguida, instalar os arquivos necessários no diretório public, executando:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake stylesheet_by_browser:<span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Serão adicionados os arquivos abaixo, no diretório public/stylesheets:</p>
<ul>
<li>chrome.css</li>
<li>firefox.css</li>
<li>ie.css</li>
<li>opera.css</li>
<li>safari.css</li>
</ul>
<p><strong>Etapa 3</strong></p>
<p>Por último, adicionar a linha abaixo no elemento HEAD do layout da aplicação:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_by_browser <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><strong>Exemplos</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_by_browser <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_by_browser <span style="color:#ff3333; font-weight:bold;">:media</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;all&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_by_browser <span style="color:#ff3333; font-weight:bold;">:media</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;print&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= stylesheet_by_browser <span style="color:#ff3333; font-weight:bold;">:media</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;screen&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p><strong>Documentação</strong></p>
<p><a href="http://lab.patrickespake.com/stylesheet_by_browser">http://lab.patrickespake.com/stylesheet_by_browser</a></p>
<p><strong>Desinstalação</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake stylesheet_by_browser:uninstall</pre></div></div>

<p><strong>Código fonte</strong></p>
<p><a href="http://github.com/patrickespake/stylesheet_by_browser/tree/master">http://github.com/patrickespake/stylesheet_by_browser/tree/master</a></p>
<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/08/03/ruby-on-rails-plugin-stylesheet_by_browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails exemplo de helper para detectar o navegador</title>
		<link>http://blog.patrickespake.com/2009/07/30/ruby-on-rails-exemplo-de-helper-para-detectar-o-navegador/</link>
		<comments>http://blog.patrickespake.com/2009/07/30/ruby-on-rails-exemplo-de-helper-para-detectar-o-navegador/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 18:55:10 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[BrowserDetect]]></category>
		<category><![CDATA[BrowserDetectHelper]]></category>
		<category><![CDATA[browser_is]]></category>
		<category><![CDATA[browser_name]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[código]]></category>
		<category><![CDATA[detectar]]></category>
		<category><![CDATA[downcase]]></category>
		<category><![CDATA[exemplo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[msie]]></category>
		<category><![CDATA[navegador]]></category>
		<category><![CDATA[nil]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[simples]]></category>
		<category><![CDATA[sucinto]]></category>
		<category><![CDATA[ua]]></category>
		<category><![CDATA[user_agent]]></category>
		<category><![CDATA[usuário]]></category>

		<guid isPermaLink="false">http://blog.patrickespake.com/?p=866</guid>
		<description><![CDATA[Esse é um exemplo simples e sucinto de um helper para detectar o navegador do usuário. Segue abaixo o código: module BrowserDetectHelper def browser_is? name browser_name == name end &#160; def browser_name ua = request.user_agent.downcase &#160; if ua =~ /firefox\// :firefox elsif ua =~ /opera\// :opera elsif ua =~ /chrome\// :chrome elsif ua =~ /safari\// [...]]]></description>
			<content:encoded><![CDATA[<p>Esse é um exemplo simples e sucinto de um helper para detectar o navegador do usuário.</p>
<p>Segue abaixo o código:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> BrowserDetectHelper
  <span style="color:#9966CC; font-weight:bold;">def</span> browser_is? name
    browser_name == name
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> browser_name
    ua = request.<span style="color:#9900CC;">user_agent</span>.<span style="color:#9900CC;">downcase</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">if</span> ua =~ <span style="color:#006600; font-weight:bold;">/</span>firefox\<span style="color:#006600; font-weight:bold;">//</span>
      <span style="color:#ff3333; font-weight:bold;">:firefox</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> ua =~ <span style="color:#006600; font-weight:bold;">/</span>opera\<span style="color:#006600; font-weight:bold;">//</span>
      <span style="color:#ff3333; font-weight:bold;">:opera</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> ua =~ <span style="color:#006600; font-weight:bold;">/</span>chrome\<span style="color:#006600; font-weight:bold;">//</span>
      <span style="color:#ff3333; font-weight:bold;">:chrome</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> ua =~ <span style="color:#006600; font-weight:bold;">/</span>safari\<span style="color:#006600; font-weight:bold;">//</span>
      <span style="color:#ff3333; font-weight:bold;">:safari</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> ua =~ <span style="color:#006600; font-weight:bold;">/</span>msie<span style="color:#006600; font-weight:bold;">/</span>
      <span style="color:#ff3333; font-weight:bold;">:ie</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/07/30/ruby-on-rails-exemplo-de-helper-para-detectar-o-navegador/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails usando strip_tags nos controllers, models e libs</title>
		<link>http://blog.patrickespake.com/2009/06/15/ruby-on-rails-usando-strip_tags-nos-controllers-models-e-libs/</link>
		<comments>http://blog.patrickespake.com/2009/06/15/ruby-on-rails-usando-strip_tags-nos-controllers-models-e-libs/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 19:46:08 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[actioncontroller]]></category>
		<category><![CDATA[actionview]]></category>
		<category><![CDATA[Base]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[exemplo]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[implementação]]></category>
		<category><![CDATA[initializers]]></category>
		<category><![CDATA[lib]]></category>
		<category><![CDATA[método]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[new_rails_defaults]]></category>
		<category><![CDATA[public_methods]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rb]]></category>
		<category><![CDATA[remover]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sanitize]]></category>
		<category><![CDATA[sanitizehelper]]></category>
		<category><![CDATA[self]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[strip_tags]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[usando]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://blog.patrickespake.com/?p=717</guid>
		<description><![CDATA[O Ruby on Rails possui o métogo strip_tags para remover tags html. Esse método está apenas disponível na camada de view, uma vez que faz parte ActionView::Helpers::SanitizeHelper. Eu não concordo com essa implementação do Rails, acho que deveria ser disponível também na camada de controller e model, onde são os lugares que esse método é [...]]]></description>
			<content:encoded><![CDATA[<p>O Ruby on Rails possui o métogo strip_tags para remover tags html. Esse método está apenas disponível na camada de <strong>view</strong>, uma vez que faz parte <strong>ActionView::Helpers::SanitizeHelper</strong>.</p>
<p>Eu não concordo com essa implementação do Rails, acho que deveria ser disponível também na camada de controller e model, onde são os lugares que esse método é mais útil.</p>
<p>Para implementar o strip_tags nos controllers, models e libs, nós podemos adicionar esse método na classe <strong>String</strong>, desta forma estará disponível em qualquer lugar.</p>
<p>Abra o arquivo <strong>config/initializers/new_rails_defaults.rb</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Be sure to restart your server when you modify this file.</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># These settings change the behavior of Rails 2 apps and will be defaults</span>
<span style="color:#008000; font-style:italic;"># for Rails 3. You can remove this initializer when Rails 3 is released.</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>ActiveRecord<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Include Active Record class name as root for JSON serialized output.</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">include_root_in_json</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Store the full class name (including module namespace) in STI type column.</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">store_full_sti_class</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Use ISO 8601 format for JSON serialized times and dates.</span>
ActiveSupport.<span style="color:#9900CC;">use_standard_json_time_format</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Don't escape HTML entities in JSON, leave that for the #json_escape helper.</span>
<span style="color:#008000; font-style:italic;"># if you're including raw json in an HTML page.</span>
ActiveSupport.<span style="color:#9900CC;">escape_html_entities_in_json</span> = <span style="color:#0000FF; font-weight:bold;">false</span></pre></td></tr></table></div>

<p>Adicione no final do arquivo as linhas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> strip_tags
    <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">helpers</span>.<span style="color:#9900CC;">strip_tags</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>As linhas acima criam o método <strong>strip_tags</strong> na classe <strong>String</strong>.</p>
<p>Ficando o arquivo completo assim:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Be sure to restart your server when you modify this file.</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># These settings change the behavior of Rails 2 apps and will be defaults</span>
<span style="color:#008000; font-style:italic;"># for Rails 3. You can remove this initializer when Rails 3 is released.</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>ActiveRecord<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Include Active Record class name as root for JSON serialized output.</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">include_root_in_json</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Store the full class name (including module namespace) in STI type column.</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">store_full_sti_class</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Use ISO 8601 format for JSON serialized times and dates.</span>
ActiveSupport.<span style="color:#9900CC;">use_standard_json_time_format</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Don't escape HTML entities in JSON, leave that for the #json_escape helper.</span>
<span style="color:#008000; font-style:italic;"># if you're including raw json in an HTML page.</span>
ActiveSupport.<span style="color:#9900CC;">escape_html_entities_in_json</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> strip_tags
    <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">helpers</span>.<span style="color:#9900CC;">strip_tags</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Agora reinicie o seu servidor web para pegar essas novas configurações na inicialização da aplicação.</p>
<p>Agora quando você precisar do strip_tags pode usar assim, exemplos:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'title'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'title'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">strip_tags</span>
&nbsp;
ou
&nbsp;
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#996600;">'&lt;b&gt;meu texto&lt;/b&gt;'</span>.<span style="color:#9900CC;">strip_tags</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;meu texto&quot;</span></pre></div></div>

<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/06/15/ruby-on-rails-usando-strip_tags-nos-controllers-models-e-libs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails usando o jQuery ao invés do Prototype</title>
		<link>http://blog.patrickespake.com/2009/06/09/ruby-on-rails-usando-o-jquery-ao-inves-do-prototype/</link>
		<comments>http://blog.patrickespake.com/2009/06/09/ruby-on-rails-usando-o-jquery-ao-inves-do-prototype/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 21:42:19 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[:defaults]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bibliotecas]]></category>
		<category><![CDATA[efeito]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[funcional]]></category>
		<category><![CDATA[googlecode]]></category>
		<category><![CDATA[heads]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[instalação]]></category>
		<category><![CDATA[javascript_include_tag]]></category>
		<category><![CDATA[jquery-ui]]></category>
		<category><![CDATA[jrails]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[libs]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Svn]]></category>
		<category><![CDATA[trunk]]></category>

		<guid isPermaLink="false">http://blog.patrickespake.com/?p=686</guid>
		<description><![CDATA[Eu gosto mais do jQuery acho ele mais leve, mais funcional e com efeitos melhores. Vou mostrar como substituir o Prototype e colocar o jQuery no seu lugar. Instalação do plugin jRails: ruby script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails No layout da sua aplicação remova o uso do Prototype, remova a linha abaixo, caso ela exista: &#60;%= javascript_include_tag [...]]]></description>
			<content:encoded><![CDATA[<p>Eu gosto mais do jQuery acho ele mais leve, mais funcional e com efeitos melhores.</p>
<p>Vou mostrar como substituir o Prototype e colocar o jQuery no seu lugar.</p>
<p>Instalação do plugin jRails:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ruby script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> http:<span style="color: #000000; font-weight: bold;">//</span>ennerchi.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>plugins<span style="color: #000000; font-weight: bold;">/</span>jrails</pre></div></div>

<p>No layout da sua aplicação remova o uso do Prototype, remova a linha abaixo, caso ela exista:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#ff3333; font-weight:bold;">:defaults</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Agora adicionei as bibliotecas javascripts entre as tags heads:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">...
  &lt;head&gt;
    ...
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;jquery&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;jquery-ui&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">&quot;jrails&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/head&gt;
...</pre></div></div>

<p>Pronto! Fazendo isso o jQuery está disponível e compatível com o Ruby on Rails, ou seja, todos os helpers javascript usarão agora o jQuery como framework javascript.</p>
<p>O plugin jRails sobrescreve os helpers javascript para usar o jQuery.</p>
<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/06/09/ruby-on-rails-usando-o-jquery-ao-inves-do-prototype/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails usando o helper Cycle de uma forma mais apurada</title>
		<link>http://blog.patrickespake.com/2009/06/09/ruby-on-rails-usando-o-helper-cycle-de-uma-forma-mais-apurada/</link>
		<comments>http://blog.patrickespake.com/2009/06/09/ruby-on-rails-usando-o-helper-cycle-de-uma-forma-mais-apurada/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 19:36:47 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[background-color]]></category>
		<category><![CDATA[cor]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[cycle]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[even]]></category>
		<category><![CDATA[exemplo]]></category>
		<category><![CDATA[foto]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ímpar]]></category>
		<category><![CDATA[lista]]></category>
		<category><![CDATA[odd]]></category>
		<category><![CDATA[par]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[reset_cycle]]></category>
		<category><![CDATA[row_photos]]></category>
		<category><![CDATA[row_videos]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tabela]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[tr]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.patrickespake.com/?p=665</guid>
		<description><![CDATA[O helper cycle é legal para trabalhar com alternância de classes css em linhas de uma tabela, divs, listas e outros elementos html. Quando você deseja que as linhas pares fiquem de uma cor e as linhas ímpares fiquem de outra cor. Por exemplo: 1 2 3 4 5 6 7 8 9 10 11 [...]]]></description>
			<content:encoded><![CDATA[<p>O helper <strong>cycle</strong> é legal para trabalhar com alternância de classes css em linhas de uma tabela, divs, listas e outros elementos html. Quando você deseja que as linhas pares fiquem de uma cor e as linhas ímpares fiquem de outra cor.</p>
<p>Por exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;table class=&quot;media-table&quot;&gt;
  &lt;caption&gt;Photos&lt;/caption&gt;
&nbsp;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th class=&quot;photo&quot;&gt;Photo&lt;/th&gt;
      &lt;th class=&quot;description&quot;&gt;Description&lt;/th&gt;
      &lt;th class=&quot;actions&quot;&gt;Actions&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
&nbsp;
  &lt;tbody&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@message</span>.<span style="color:#9900CC;">photos</span>.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">%&gt;</span>
      <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">for</span> photo <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#0066ff; font-weight:bold;">@message</span>.<span style="color:#9900CC;">photos</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
        &lt;tr class=&quot;<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&quot;&gt;
          &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag photo.<span style="color:#9900CC;">file</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:thumb</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/td&gt;
          &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= photo.<span style="color:#9900CC;">description</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/td&gt;
          &lt;td class=&quot;actions&quot;&gt;
            <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to_delete message_photo_path<span style="color:#006600; font-weight:bold;">&#40;</span>@message, photo<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
          &lt;/td&gt;
        &lt;/tr&gt;
      <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      &lt;tr&gt;
        &lt;td colspan=&quot;3&quot;&gt;No photos.&lt;/td&gt;
      &lt;/tr&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/tbody&gt;
&lt;/table&gt;</pre></td></tr></table></div>

<p>E você pode ter uma regra css da seguinte forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">table.media-table tr.even {
}
&nbsp;
table.media-table tr.odd {
  background-color: #e5eefa;
}</pre></td></tr></table></div>

<p>Desta forma todas as linhas ímpares ficaram de uma cor diferente.</p>
<p>É um helper bem simples que permite deixar suas tabelas, divs, listas e outros itens htmls bem legíveis através de regras css adequadas.</p>
<p>Você pode encontrar um problema de estilização quando usar o helper <strong>cycle</strong> em duas tabelas distintas conforme exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;table class=&quot;media-table&quot;&gt;
  &lt;caption&gt;Photos&lt;/caption&gt;
&nbsp;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th class=&quot;photo&quot;&gt;Photo&lt;/th&gt;
      &lt;th class=&quot;description&quot;&gt;Description&lt;/th&gt;
      &lt;th class=&quot;actions&quot;&gt;Actions&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
&nbsp;
  &lt;tbody&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@message</span>.<span style="color:#9900CC;">photos</span>.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">%&gt;</span>
      <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">for</span> photo <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#0066ff; font-weight:bold;">@message</span>.<span style="color:#9900CC;">photos</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
        &lt;tr class=&quot;<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&quot;&gt;
          &lt;td&gt;&lt; %= image_tag photo.file.url(:thumb) %&gt;&lt;/td&gt;
          &lt;td&gt;&lt; %= photo.description %&gt;&lt;/td&gt;
          &lt;td class=&quot;actions&quot;&gt;
            <span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to_delete message_photo_path<span style="color:#006600; font-weight:bold;">&#40;</span>@message, photo<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
          &lt;/td&gt;
        &lt;/tr&gt;
      <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      &lt;tr&gt;
        &lt;td colspan=&quot;3&quot;&gt;No photos.&lt;/td&gt;
      &lt;/tr&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/tbody&gt;
&lt;/table&gt;
&nbsp;
&lt;br /&gt;
&lt;br /&gt;
&nbsp;
&lt;table class=&quot;media-table&quot;&gt;
  &lt;caption&gt;Videos&lt;/caption&gt;
&nbsp;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th class=&quot;video&quot;&gt;Video&lt;/th&gt;
      &lt;th class=&quot;description&quot;&gt;Description&lt;/th&gt;
      &lt;th class=&quot;actions&quot;&gt;Actions&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
&nbsp;
  &lt;tbody&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@message</span>.<span style="color:#9900CC;">videos</span>.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">for</span> video <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#0066ff; font-weight:bold;">@message</span>.<span style="color:#9900CC;">videos</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
        &lt;tr class=&quot;<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&quot;&gt;
          &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= video.<span style="color:#9900CC;">file</span>.<span style="color:#9900CC;">url</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/td&gt;
          &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= video.<span style="color:#9900CC;">description</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/td&gt;
          &lt;td&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to_delete message_video_path<span style="color:#006600; font-weight:bold;">&#40;</span>@message, video<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/td&gt;
        &lt;/tr&gt;
      <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      &lt;tr&gt;
        &lt;td colspan=&quot;3&quot;&gt;No videos.&lt;/td&gt;
      &lt;/tr&gt;
    <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/tbody&gt;
&lt;/table&gt;</pre></td></tr></table></div>

<p>No exemplo acima nós temos duas tabelas, uma para as fotos e outra para os vídeos. Nessa situação pode acontecer da próxima linha da tabela de vídeos ser pintada com a regra css odd, caso o número de linhas da tabela de fotos seja par.</p>
<p>Isso acontece por que o helper <strong>cycle</strong> não zera o seu contador  entre um uso e outro.</p>
<p>Para trabalhar adequadamente você pode dar um nome para cada uso do helper <strong>cycle</strong>, desta forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">...
<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span>, <span style="color:#996600;">'row_photos'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
...
<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span>, <span style="color:#996600;">'row_videos'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
...</pre></td></tr></table></div>

<p>Fazendo isso cada uso do helper <strong>cycle</strong> terá o seu próprio contador, e o problema de pintar o cabeçalho da tabela não ocorre mais.</p>
<p>Existe uma outra opção, você pode usar o helper <strong>cycle</strong> como mencionado no primeiro exemplo, sem definir um nome para cada uso do helper <strong>cycle</strong>, entre um uso e outro do helper <strong>cycle</strong> você pode pedir para zerar o seu contador, chamando o helper <strong>reset_cycle</strong>, exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">...
<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
...
<span style="color:#006600; font-weight:bold;">&lt;%</span> reset_cycle <span style="color:#006600; font-weight:bold;">%&gt;</span>
...
<span style="color:#006600; font-weight:bold;">&lt;%</span>= cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'even'</span>, <span style="color:#996600;">'odd'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
...</pre></td></tr></table></div>

<p>O helper <strong>reset_cycle</strong> também aceita zerar apenas um determinado helper <strong>cycle</strong>, basta informar o nome que você deseja zerar:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> reset_cycle<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;row_photos&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/06/09/ruby-on-rails-usando-o-helper-cycle-de-uma-forma-mais-apurada/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails time_ago_in_words</title>
		<link>http://blog.patrickespake.com/2009/06/05/ruby-on-rails-time_ago_in_words/</link>
		<comments>http://blog.patrickespake.com/2009/06/05/ruby-on-rails-time_ago_in_words/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 19:04:33 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[from_now]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[minutes]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sourcecode]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[time_ago_in_words]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=653</guid>
		<description><![CDATA[Gosto muito de algumas coisas simples do Rails, o helper time_ago_in_words é uma delas, serve para escrever a quanto tempo ocorreu a partir da data atual. Por exemplo: 1 2 3 time_ago_in_words&#40;3.minutes.from_now&#41; # =&#62; 3 minutes time_ago_in_words&#40;Time.now - 15.hours&#41; # =&#62; 15 hours time_ago_in_words&#40;Time.now&#41; # =&#62; less than a minute Outro exemplo: 1 2 3 [...]]]></description>
			<content:encoded><![CDATA[<p>Gosto muito de algumas coisas simples do Rails, o helper <strong>time_ago_in_words</strong> é uma delas, serve para escrever a quanto tempo ocorreu a partir da data atual.</p>
<p>Por exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">time_ago_in_words<span style="color:#006600; font-weight:bold;">&#40;</span>3.<span style="color:#9900CC;">minutes</span>.<span style="color:#9900CC;">from_now</span><span style="color:#006600; font-weight:bold;">&#41;</span>       <span style="color:#008000; font-style:italic;"># =&gt; 3 minutes</span>
time_ago_in_words<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> 15.<span style="color:#9900CC;">hours</span><span style="color:#006600; font-weight:bold;">&#41;</span>      <span style="color:#008000; font-style:italic;"># =&gt; 15 hours</span>
time_ago_in_words<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span><span style="color:#006600; font-weight:bold;">&#41;</span>                 <span style="color:#008000; font-style:italic;"># =&gt; less than a minute</span></pre></td></tr></table></div>

<p>Outro exemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;ol class=&quot;timeline&quot;&gt;
  &lt;li&gt; 
    &lt;span class=&quot;title&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= draft.<span style="color:#9900CC;">title</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/span&gt;
    &lt;span class=&quot;updated_at&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= time_ago_in_words<span style="color:#006600; font-weight:bold;">&#40;</span>draft.<span style="color:#9900CC;">updated_at</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span> ago&lt;/span&gt;
  &lt;/li&gt;
&lt;/ol&gt;</pre></td></tr></table></div>

<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/06/05/ruby-on-rails-time_ago_in_words/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails como fazer dois atributos da mesma classe apontarem para a mesma classe pai no ActiveRecord</title>
		<link>http://blog.patrickespake.com/2009/03/23/ruby-on-rails-como-fazer-dois-atributos-da-mesma-classe-apontarem-para-a-mesma-classe-pai-no-activerecord/</link>
		<comments>http://blog.patrickespake.com/2009/03/23/ruby-on-rails-como-fazer-dois-atributos-da-mesma-classe-apontarem-para-a-mesma-classe-pai-no-activerecord/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 19:20:25 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[all]]></category>
		<category><![CDATA[atributos]]></category>
		<category><![CDATA[BackendMenu]]></category>
		<category><![CDATA[belongs_to]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[classe]]></category>
		<category><![CDATA[class_name]]></category>
		<category><![CDATA[conditions]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[delete_all]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[foreign_key]]></category>
		<category><![CDATA[has_many]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[item_nodes]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[menu_items]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[nó]]></category>
		<category><![CDATA[nodes]]></category>
		<category><![CDATA[nós]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=497</guid>
		<description><![CDATA[Hoje estava programando um sistema de menus, onde cada item de menu pode ter vários outros itens, não existindo limite de subníveis. Para conseguir obter essa relação e associação no banco de dados criei dois models BackendMenu e BackendMenuNode, com as seguintes migrações: BackendMenu: 1 2 3 4 5 6 7 8 9 10 11 [...]]]></description>
			<content:encoded><![CDATA[<p>Hoje estava programando um sistema de menus, onde cada item de menu pode ter vários outros itens, não existindo limite de subníveis.</p>
<p>Para conseguir obter essa relação e associação no banco de dados criei dois models <strong>BackendMenu</strong> e <strong>BackendMenuNode</strong>, com as seguintes migrações:</p>
<p>BackendMenu:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateBackendMenus <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:backend_menus</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span>  <span style="color:#ff3333; font-weight:bold;">:title</span>,     <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span>  <span style="color:#ff3333; font-weight:bold;">:path</span>,      <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:weight</span>,    <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span>
      t.<span style="color:#9900CC;">boolean</span> <span style="color:#ff3333; font-weight:bold;">:is_active</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      t.<span style="color:#9900CC;">boolean</span> <span style="color:#ff3333; font-weight:bold;">:is_root</span>,   <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      t.<span style="color:#9900CC;">timestamps</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    drop_table <span style="color:#ff3333; font-weight:bold;">:backend_menus</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>BackendMenuNode:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateBackendMenuNodes <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:backend_menu_nodes</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:root_id</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:node_id</span>, <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#ff3333; font-weight:bold;">:weight</span>,  <span style="color:#ff3333; font-weight:bold;">:null</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    add_index<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:backend_menu_nodes</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span>, <span style="color:#ff3333; font-weight:bold;">:node_id</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:unique</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    execute <span style="color:#996600;">&quot;ALTER TABLE backend_menu_nodes ADD CONSTRAINT fk_backend_menu_nodes_backend_menus_root FOREIGN KEY (root_id) REFERENCES backend_menus (id) ON DELETE CASCADE ON UPDATE CASCADE&quot;</span>
    execute <span style="color:#996600;">&quot;ALTER TABLE backend_menu_nodes ADD CONSTRAINT fk_backend_menu_nodes_backend_menus_node FOREIGN KEY (node_id) REFERENCES backend_menus (id) ON DELETE CASCADE ON UPDATE CASCADE&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    drop_table <span style="color:#ff3333; font-weight:bold;">:backend_menu_nodes</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Todos os itens de menu vão ficar cadastrados na tabela <strong>backend_menus</strong> e associação para descobrir os menus filhos será feito pela tabela <strong>backend_menu_nodes</strong>. A tabela <strong>backend_menu_nodes </strong>tem as colunas <strong>root_id</strong> que se referência ao pai e a coluna <strong>node_id</strong> que se referência aos menus filhos, desta forma um menu pode ter N itens.</p>
<p>Tanto a coluna <strong>root_id</strong> e <strong>node_id</strong> fazem referência a tabela <strong>backend_menus</strong>.</p>
<p>Para conseguir obter essa associação no ActiveRecord fiz o seguinte:</p>
<p><strong>BackendMenu:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> BackendMenu <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;"># associações</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:nodes</span>, <span style="color:#ff3333; font-weight:bold;">:class_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;BackendMenuNode&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:foreign_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;root_id&quot;</span>
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><strong>BackendMenuNode:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> BackendMenuNode <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;"># associações</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:root</span>, <span style="color:#ff3333; font-weight:bold;">:class_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;BackendMenu&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:foreign_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;root_id&quot;</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:node</span>, <span style="color:#ff3333; font-weight:bold;">:class_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;BackendMenu&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:foreign_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;node_id&quot;</span>
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Fazendo a relação acima eu consigo navegar pelo menu pai e os meus filhos.</p>
<p>Para imprimir o menu eu criei 3 helpers usando a recursividade:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> BackendHelper
&nbsp;
  <span style="color:#008000; font-style:italic;"># cria o menu do backend</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> menu<span style="color:#006600; font-weight:bold;">&#40;</span>collection, class_name = <span style="color:#996600;">&quot;menu&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    content = content_tag <span style="color:#ff3333; font-weight:bold;">:ul</span>, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> class_name <span style="color:#9966CC; font-weight:bold;">do</span>
      menu_items<span style="color:#006600; font-weight:bold;">&#40;</span>collection<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    content
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># cria os items do menu</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> menu_items<span style="color:#006600; font-weight:bold;">&#40;</span>collection<span style="color:#006600; font-weight:bold;">&#41;</span>
    content = <span style="color:#996600;">&quot;&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">for</span> item <span style="color:#9966CC; font-weight:bold;">in</span> collection
      <span style="color:#9966CC; font-weight:bold;">if</span> item.<span style="color:#9900CC;">instance_of</span>? BackendMenu
        content <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> item_nodes<span style="color:#006600; font-weight:bold;">&#40;</span>item<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        content <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> item_nodes<span style="color:#006600; font-weight:bold;">&#40;</span>item.<span style="color:#9900CC;">node</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    content
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># cria os nós do item de menu</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> item_nodes<span style="color:#006600; font-weight:bold;">&#40;</span>item<span style="color:#006600; font-weight:bold;">&#41;</span>
    content = <span style="color:#996600;">&quot;&quot;</span>
    class_name = <span style="color:#996600;">&quot;leaf&quot;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">if</span> item.<span style="color:#9900CC;">nodes</span>.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span>
      class_name = <span style="color:#996600;">&quot;collapsed&quot;</span>
      content <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> content_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:li</span>, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> class_name<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        link_to<span style="color:#006600; font-weight:bold;">&#40;</span>item.<span style="color:#9900CC;">title</span>, item.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> menu<span style="color:#006600; font-weight:bold;">&#40;</span>item.<span style="color:#9900CC;">nodes</span>, <span style="color:#996600;">&quot;menu hide&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      content <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> content_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:li</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span>item.<span style="color:#9900CC;">title</span>, item.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> class_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    content
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>No controlador eu faço o seguinte:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@backend_menus</span> = BackendMenu.<span style="color:#9900CC;">find</span> <span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'weight'</span></pre></td></tr></table></div>

<p>Na view:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;!-- begin sidebar-left --&gt;
&lt;div id=&quot;sidebar-left&quot;&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= menu<span style="color:#006600; font-weight:bold;">&#40;</span>@backend_menus<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&lt;/div&gt;
&lt;!-- end sidebar-left --&gt;</pre></td></tr></table></div>

<p>Se você quiser alguns menus de teste, usei a migração abaixo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> AddBackendMenus <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    BackendMenu.<span style="color:#9900CC;">delete_all</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># criação dos menus pais</span>
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Principal'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'principal'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Criar Conteúdo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'criar-conteudo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Gerenciamento de Conteúdo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Site Construtor'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Site Configuração'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-configuracao'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Gerenciamento de Usuário'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-usuario'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">6</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Relatórios'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'relatorios'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Ajuda'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'ajuda'</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">8</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># criação dos menus filhos</span>
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Página'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'criar-conteudo/pagina'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'criar-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'criar-conteudo/pagina'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'História'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'criar-conteudo/historia'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'criar-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'criar-conteudo/historia'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Comentários'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/comentarios'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Ativos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/ativos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/ativos'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Teste'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/ativos/teste'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/ativos'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/ativos/teste'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Inativos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/inativos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/comentarios/inativos'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Conteúdo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/conteudo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Tipos de Conteúdo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/tipos-de-conteudo'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/tipos-de-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Publicação de RSS'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-conteudo/publicacao-de-rss'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-conteudo/publicacao-de-rss'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Blocos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor/blocos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor/blocos'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Formulários'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor/formularios'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor/formularios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Menus'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor/menus'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor/menus'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Módulos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor/modulos'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor/modulos'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'temas'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor/temas'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor/temas'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Tradução'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-construtor/traducao'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-construtor/traducao'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Idiomas'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-configuracao/idiomas'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao/idiomas'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Logs e Alertas'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-configuracao/logs-e-alertas'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao/logs-e-alertas'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Manutenção do Site'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-configuracao/manuencao-do-site'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao/manuencao-do-site'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Ações'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'site-configuracao/acoes'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'site-configuracao/acoes'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Regras de Acesso'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-usuario/regras-de-acesso'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario/regras-de-acesso'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Permissões'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-usuario/permissoes'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario/permissoes'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Regras'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-usuario/regras'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario/regras'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Configurações de Usuários'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-usuario/configuracoes-de-usuarios'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario/configuracoes-de-usuarios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Usuários'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'gerenciamento-de-usuario/usuarios'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'gerenciamento-de-usuario/usuarios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Entrada de Logs'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'relatorios/entrada-de-logs'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'relatorios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'relatorios/entrada-de-logs'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Erros de Acesso Negado'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'relatorios/erros-de-acesso-negado'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'relatorios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'relatorios/erros-de-acesso-negado'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    BackendMenu.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Status'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'relatorios/status'</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
      <span style="color:#ff3333; font-weight:bold;">:is_root</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    BackendMenuNode.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:root_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'relatorios'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:node_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BackendMenu.<span style="color:#9900CC;">find_by_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'relatorios/status'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">id</span>,
      <span style="color:#ff3333; font-weight:bold;">:weight</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    BackendMenu.<span style="color:#9900CC;">delete_all</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/03/23/ruby-on-rails-como-fazer-dois-atributos-da-mesma-classe-apontarem-para-a-mesma-classe-pai-no-activerecord/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails uma forma mais inteligente de organizar controladores e helpers</title>
		<link>http://blog.patrickespake.com/2009/03/18/ruby-on-rails-uma-forma-mais-inteligente-de-organizar-controladores-e-helpers/</link>
		<comments>http://blog.patrickespake.com/2009/03/18/ruby-on-rails-uma-forma-mais-inteligente-de-organizar-controladores-e-helpers/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 20:47:38 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ActionController::Base]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[aplicação]]></category>
		<category><![CDATA[applicationcontroller]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[backend_controller.rb]]></category>
		<category><![CDATA[conceito]]></category>
		<category><![CDATA[controlador]]></category>
		<category><![CDATA[controladores]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[herança]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[ideia]]></category>
		<category><![CDATA[organizar]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=488</guid>
		<description><![CDATA[Estou trabalhando numa nova aplicação em Rails, ela é dividida em área administrativa e uma área vísivel a todos os visitantes da aplicação. Inicialmente eu comecei com os controladores admin_controller.erb, home_controller.erb e o controlador padrão application_controller.erb, que é herdado pelos dois primeiros controladores. application_controller.erb 1 2 3 4 5 6 7 8 9 10 # [...]]]></description>
			<content:encoded><![CDATA[<p>Estou trabalhando numa nova aplicação em Rails, ela é dividida em área administrativa e uma área vísivel a todos os visitantes da aplicação.</p>
<p>Inicialmente eu comecei com os controladores admin_controller.erb, home_controller.erb e o controlador padrão application_controller.erb, que é herdado pelos dois primeiros controladores.</p>
<p>application_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Filters added to this controller apply to all controllers in the application.</span>
<span style="color:#008000; font-style:italic;"># Likewise, all the methods added will be available for all controllers.</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  helper <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#008000; font-style:italic;"># include all helpers, all the time</span>
  protect_from_forgery <span style="color:#008000; font-style:italic;"># See ActionController::RequestForgeryProtection for details</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Scrub sensitive parameters from your log</span>
  <span style="color:#008000; font-style:italic;"># filter_parameter_logging :password</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>admin_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> AdminController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>home_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> HomeController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Mas eu quero deixar a minha aplicação mais simples e inteligente, a minha área administrativa vai ser grande, bem como o meu frontend.</p>
<p>Vão existir uma série de filtros e helpers que vão ser usados em comum por todos os diversos controladores da área administrativa e do frontend, do jeito que está hoje eu teria que colocar muito código no application_controller.erb, bem como no helper padrão application_helper.erb.</p>
<p>Desta forma eu decidi criar dois novos controladores backend_controller.erb e frontend_controller.erb, a minha ideia é fazer todos os controladores da área administrativa herdarem o backend_controller.erb, e todos os controladores do meu frontend herdarem o controlador frontend_controller.erb. Por sua vez os controladores backend_controller.erb e frontend_controller.erb herdarão o application_controller.erb, o que garante que a minha aplicação vai continuar funcionando corretamente.</p>
<p>Fazendo isso eu ganho um grau maior de componentização dos controladores, quando eu adicionar um filtro, método ou helper no backend_controller.erb ou frontend_controller.erb todos os controladores filhos deles já terão essa funcionalidade disponível.</p>
<p>Seguindo essa ideia eu fiz algumas alterações para implementar esse recurso:</p>
<p>Criei dois novos controladores:</p>
<p>backend_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Filtros adicionados nesse controlador serão aplicados em todos os controladores filhos</span>
<span style="color:#008000; font-style:italic;"># De igual modo, todos os métodos adicionados estarão disponíveis para todos os controladores filhos</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> BackendController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>frontend_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Filtros adicionados nesse controlador serão aplicados em todos os controladores filhos</span>
<span style="color:#008000; font-style:italic;"># De igual modo, todos os métodos adicionados estarão disponíveis para todos os controladores filhos</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> FrontendController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Alterei os controladores abaixo, para herdarem os controladores criados acimas:</p>
<p>admin_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> AdminController <span style="color:#006600; font-weight:bold;">&lt;</span> BackendController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>home_controller.erb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> HomeController <span style="color:#006600; font-weight:bold;">&lt;</span> FrontendController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Fazendo isso eu consigo ganhar uma componentização muito grande, se eu adicionar alguma coisa no controlador application_controller.erb, ele está disponível tanto no admin como no frontend.</p>
<p>Adicionando algo no frontend_controller.erb estará disponível em todo o frontend e adicionando algo no backend_controller.erb estará disponível em todo o admin.</p>
<p>É possível melhorar mais ainda, vamos criar dois novos helpers:</p>
<p>backend_helper.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> BackendHelper
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>frontend_helper.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> FrontendHelper
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Vou colocar esses helpers para serem carregados em todos os controladores que herdam backend_controller.rb e frontend_controller.erb:</p>
<p>backend_controller.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Filtros adicionados nesse controlador serão aplicados em todos os controladores filhos</span>
<span style="color:#008000; font-style:italic;"># De igual modo, todos os métodos adicionados estarão disponíveis para todos os controladores filhos</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> BackendController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  layout <span style="color:#996600;">&quot;admin&quot;</span>
  helper <span style="color:#ff3333; font-weight:bold;">:backend</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Acima eu aproveitei e adicionei o layout &#8220;admin.html.erb&#8221;, que será usado por todos as views da área administrativa.</p>
<p>frontend_controller.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Filtros adicionados nesse controlador serão aplicados em todos os controladores filhos</span>
<span style="color:#008000; font-style:italic;"># De igual modo, todos os métodos adicionados estarão disponíveis para todos os controladores filhos</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> FrontendController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  helper <span style="color:#ff3333; font-weight:bold;">:frontend</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Agora no application_controller.erb, comente a linha helper :all, para não carregar todos os helpers, só os que você precisa.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Filters added to this controller apply to all controllers in the application.</span>
<span style="color:#008000; font-style:italic;"># Likewise, all the methods added will be available for all controllers.</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  <span style="color:#008000; font-style:italic;"># helper :all # include all helpers, all the time</span>
  protect_from_forgery <span style="color:#008000; font-style:italic;"># See ActionController::RequestForgeryProtection for details</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Scrub sensitive parameters from your log</span>
  <span style="color:#008000; font-style:italic;"># filter_parameter_logging :password</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Pronto! ;-)</p>
<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/03/18/ruby-on-rails-uma-forma-mais-inteligente-de-organizar-controladores-e-helpers/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails 2.2 Como Criar Rss Feed</title>
		<link>http://blog.patrickespake.com/2009/02/07/ruby-on-rails-22-como-criar-rss-feed/</link>
		<comments>http://blog.patrickespake.com/2009/02/07/ruby-on-rails-22-como-criar-rss-feed/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 19:24:37 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[auto_discovery]]></category>
		<category><![CDATA[auto_discovery_link_tag]]></category>
		<category><![CDATA[content_for]]></category>
		<category><![CDATA[criar]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[formatted]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[index.html.erb]]></category>
		<category><![CDATA[index.rss.builder]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[map.resources]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 2.2]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[rss feed]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[will_paginate]]></category>
		<category><![CDATA[xml.channel]]></category>
		<category><![CDATA[xml.description]]></category>
		<category><![CDATA[xml.guid]]></category>
		<category><![CDATA[xml.instruct]]></category>
		<category><![CDATA[xml.item]]></category>
		<category><![CDATA[xml.link]]></category>
		<category><![CDATA[xml.pubDate]]></category>
		<category><![CDATA[xml.rss]]></category>
		<category><![CDATA[xml.title]]></category>
		<category><![CDATA[yield]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=469</guid>
		<description><![CDATA[Hoje vou mostrar como criar Rss Feed no Ruby on Rails 2.2, no final você vai dar risada, de tão simples que é. Vamos lá! Geralmente a action index é responsável por fazer a listagem das informações, ela pode ser parecer com isso: 1 2 3 def index @histories = History.find :all, :limit =&#62; 10 [...]]]></description>
			<content:encoded><![CDATA[<p>Hoje vou mostrar como criar Rss Feed no Ruby on Rails 2.2, no final você vai dar risada, de tão simples que é. Vamos lá!</p>
<p>Geralmente a <strong>action index</strong> é responsável por fazer a listagem das informações, ela pode ser parecer com isso:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#0066ff; font-weight:bold;">@histories</span> = History.<span style="color:#9900CC;">find</span> <span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>ou como abaixo, quando você está usando o plugin will_paginate:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#0066ff; font-weight:bold;">@histories</span> = History.<span style="color:#9900CC;">paginate</span> <span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:page</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Não vamos precisar mexer em nada na <strong>action index</strong>.</p>
<p>Você precisa criar um novo template chamado <strong>index.rss.builder</strong>, que deve estar localizado em <strong>app/views/histories/index.rss.builder</strong> com o seguinte conteúdo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">xml.<span style="color:#9900CC;">instruct</span>! <span style="color:#996600;">'xml'</span>, <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;1.0&quot;</span>
xml.<span style="color:#9900CC;">rss</span> <span style="color:#ff3333; font-weight:bold;">:version</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;2.0&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  xml.<span style="color:#9900CC;">channel</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    xml.<span style="color:#9900CC;">title</span> <span style="color:#996600;">&quot;Notícias&quot;</span>
    xml.<span style="color:#9900CC;">description</span> <span style="color:#996600;">&quot;Últimas Notícias&quot;</span>
    xml.<span style="color:#9900CC;">language</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'pt-BR'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    xml.<span style="color:#9900CC;">link</span> formatted_histories_url<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rss</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">for</span> history <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#0066ff; font-weight:bold;">@histories</span>
      xml.<span style="color:#9900CC;">item</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        xml.<span style="color:#9900CC;">title</span> history.<span style="color:#9900CC;">title</span>
        xml.<span style="color:#9900CC;">description</span> history.<span style="color:#9900CC;">content</span>
        xml.<span style="color:#9900CC;">pubDate</span> history.<span style="color:#9900CC;">created_at</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rfc822</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        xml.<span style="color:#9900CC;">link</span> history_url<span style="color:#006600; font-weight:bold;">&#40;</span>history<span style="color:#006600; font-weight:bold;">&#41;</span>
        xml.<span style="color:#9900CC;">guid</span> history_url<span style="color:#006600; font-weight:bold;">&#40;</span>history<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Pronto! O que você não acredita que está pronto? É verdade falta adicionar o link no template <strong>index.html.erb</strong> para ver o Rss Feed.</p>
<p>No template index.html.erb adicione:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= link_to <span style="color:#996600;">&quot; RSS Feed&quot;</span>, formatted_histories_url<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rss</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Para acessar o Rss Feed visite: <strong>http://localhost:3000/histories.rss</strong>.</p>
<p>Não esqueça de definir no seu arquivo <strong>config/routes.rb</strong> que o model history trabalha com urls RESTful:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:histories</span></pre></td></tr></table></div>

<p>Uhmm! Não estou feliz ainda, acho que dá para melhorar mais, é verdade podemos adicionar:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">	&lt;link href=&quot;http://localhost:3000/histories.rss&quot; rel=&quot;alternate&quot; title=&quot;RSS&quot; type=&quot;application/rss+xml&quot; /&gt;</pre></td></tr></table></div>

<p>Entre as tags:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;head&gt;...&lt;/head&gt;</pre></td></tr></table></div>

<p>do HTML, fazendo isso o navegador adiciona o ícone de Feed na barra de endereço e deixa a coisa mais intuitiva para o usuário.</p>
<p>Vamos fazer isso de uma forma mais elegante e dinâmica.</p>
<p>No layout da sua aplicação adicionei <strong>yield :auto_discovery</strong> entre as tags <strong>head</strong> do HTML:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;head&gt;
...
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#ff3333; font-weight:bold;">:auto_discovery</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
...
&lt;/head&gt;</pre></td></tr></table></div>

<p>Agora no template <strong>index.html.erb</strong> adicione:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> content_for <span style="color:#ff3333; font-weight:bold;">:auto_discovery</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= auto_discovery_link_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rss</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:index</span>, <span style="color:#ff3333; font-weight:bold;">:format</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:rss</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Agora sim ficou legal! ;-)</p>
<p>Mais informações assista aqui: <a href="http://media.railscasts.com/videos/087_generating_rss.mov">http://media.railscasts.com/videos/087_generating_rss.mov</a>.</p>
<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/02/07/ruby-on-rails-22-como-criar-rss-feed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://media.railscasts.com/videos/087_generating_rss.mov" length="13030929" type="video/quicktime" />
<enclosure url="http://media.railscasts.com/videos/087_generating_rss.mov" length="13030929" type="video/quicktime" />
		</item>
		<item>
		<title>Ruby on Rails helper para criar o Mapa do Site</title>
		<link>http://blog.patrickespake.com/2009/02/06/ruby-on-rails-helper-para-criar-o-mapa-do-site/</link>
		<comments>http://blog.patrickespake.com/2009/02/06/ruby-on-rails-helper-para-criar-o-mapa-do-site/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 20:22:38 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[content_tag]]></category>
		<category><![CDATA[each]]></category>
		<category><![CDATA[error404]]></category>
		<category><![CDATA[generate_map]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[li]]></category>
		<category><![CDATA[link_to]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[mapa]]></category>
		<category><![CDATA[mapa do site]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[recursividade]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[site map]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[ul]]></category>
		<category><![CDATA[value]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=464</guid>
		<description><![CDATA[Hoje eu precisei criar o &#8220;Mapa do Site&#8221;, conforme imagem acima, procurei por alguns plugins para fazer isso, mas infelizmente não encontrei nada da forma que eu queria, então resolvi implementar o meu próprio helper. Através das tags htmls ul e li é possível gerar essa estrutura. Para implementar essa funcionalidade eu desenvolvi o seguinte [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_466" class="wp-caption aligncenter" style="width: 196px"><img class="size-full wp-image-466" title="Mapa do Site" src="http://patrickespake.files.wordpress.com/2009/02/mapa_do_site.png" alt="Mapa do Site" width="196" height="312" /><p class="wp-caption-text">Mapa do Site</p></div>
<p>Hoje eu precisei criar o <strong>&#8220;Mapa do Site&#8221;</strong>, conforme imagem acima, procurei por alguns plugins para fazer isso, mas infelizmente não encontrei nada da forma que eu queria, então resolvi implementar o meu próprio helper.</p>
<p>Através das tags htmls <strong>ul</strong> e <strong>li</strong> é possível gerar essa estrutura.</p>
<p>Para implementar essa funcionalidade eu desenvolvi o seguinte helper:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> SitemapHelper
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> sitemap
    map =
    <span style="color:#006600; font-weight:bold;">&#123;</span>
      link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Página Inicial&quot;</span>, root_url<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span>
        <span style="color:#006600; font-weight:bold;">&#123;</span>
          <span style="color:#996600;">&quot;Informação&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Notícias&quot;</span>, histories_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Newsletters&quot;</span>, newsletters_path<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          <span style="color:#996600;">&quot;Capacitação e Aperfeiçoamento&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Serviços&quot;</span>, services_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Institucionais&quot;</span>, institutionals_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Eventos&quot;</span>, events_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Melhores Práticas&quot;</span>, best_practices_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Podcasts&quot;</span>, podcasts_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Tvs&quot;</span>, tvs_path<span style="color:#006600; font-weight:bold;">&#41;</span>, link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Degustações&quot;</span>, tastings_path<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          <span style="color:#996600;">&quot;Editora&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Produtos&quot;</span>, products_path<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          link_to<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Grupo&quot;</span>, groups_path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
        <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    content_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:ul</span>, generate_map<span style="color:#006600; font-weight:bold;">&#40;</span>map<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> generate_map<span style="color:#006600; font-weight:bold;">&#40;</span>elements<span style="color:#006600; font-weight:bold;">&#41;</span>
    html = <span style="color:#996600;">''</span>
&nbsp;
    elements.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>key, value<span style="color:#006600; font-weight:bold;">|</span>
      html <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> content_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:li</span>, key<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">if</span> !value.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">and</span> value.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span>
        html <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> content_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:ul</span>, generate_map<span style="color:#006600; font-weight:bold;">&#40;</span>value.<span style="color:#9900CC;">sort</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#0000FF; font-weight:bold;">return</span> html
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>No código acima eu criei um método chamado <strong>sitemap</strong>, dentro desse método existe um <strong>hash</strong> chamado <strong>map</strong>, nesse hash eu defino a hierarquia dos links.</p>
<p>O outro método é o <strong>generate_map</strong>, ele é responsável por gerar a estrutura html em listas através das tags html <strong>ul</strong> e <strong>li</strong>. Esse método usa recursividade (o grande amigo dos programadores ;-)).</p>
<p>Feito tudo isso, agora no template eu só chamo o helper, por exemplo no <strong>index.html.erb</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= sitemap <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>É possível chamar esse helper nos templates de erro 404, assim melhora a navegação para o usuário.</p>
<p>Se você gostou desse texto e acha que ajudou você, me recomende: <a href="http://www.workingwithrails.com/recommendation/new/person/15479-patrick-espake"><img src="http://workingwithrails.com/images/tools/compact-small-button.jpg" alt="Recommend Me" /></a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.patrickespake.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.patrickespake.com/2009/02/06/ruby-on-rails-helper-para-criar-o-mapa-do-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
