<?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; imagemagick</title>
	<atom:link href="http://blog.patrickespake.com/tag/imagemagick/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 configurando ambiente de desenvolvimento no Linux</title>
		<link>http://blog.patrickespake.com/2009/06/25/ruby-on-rails-configurando-ambiente-de-desenvolvimento-no-linux/</link>
		<comments>http://blog.patrickespake.com/2009/06/25/ruby-on-rails-configurando-ambiente-de-desenvolvimento-no-linux/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 01:41:34 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[127.0.0.1]]></category>
		<category><![CDATA[ambiente]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[aplicação]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[configurando]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[desenvolvimento]]></category>
		<category><![CDATA[documentroot]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[minha aplicação]]></category>
		<category><![CDATA[modrails]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysql-server]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rdoc]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rubygems]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[sites-available]]></category>
		<category><![CDATA[sites-enabled]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[virtual host]]></category>

		<guid isPermaLink="false">http://blog.patrickespake.com/?p=749</guid>
		<description><![CDATA[Nesse post vou mostrar como configurar um ambiente de desenvolvimento em Ruby on Rails no Linux. Vamos lá! Atualizando os pacotes do Linux: sudo apt-get update Instalando Ruby on Rails: 1 2 3 4 5 6 7 8 9 10 sudo apt-get install ruby irb rdoc ruby1.8-dev libopenssl-ruby imagemagick curl wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz tar xzvf rubygems-1.3.4.tgz [...]]]></description>
			<content:encoded><![CDATA[<p>Nesse post vou mostrar como configurar um ambiente de desenvolvimento em Ruby on Rails no Linux.</p>
<p>Vamos lá!</p>
<p><strong>Atualizando os pacotes do Linux:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update</pre></div></div>

<p><strong>Instalando Ruby on Rails:</strong></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="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ruby irb rdoc ruby1.8-dev libopenssl-ruby imagemagick curl
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">57643</span><span style="color: #000000; font-weight: bold;">/</span>rubygems-1.3.4.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf rubygems-1.3.4.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> rubygems-1.3.4
<span style="color: #c20cb9; font-weight: bold;">sudo</span> ruby setup.rb
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> gem1.8 gem
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails passenger mongrel capistrano</pre></td></tr></table></div>

<p><strong>Instalando Apache com PHP e Passenger/Modrails:</strong></p>
<p>O Passenger/Modrails permite rodar aplicações Ruby on Rails no Apache.<br />
Nessa etapa nós também iremos instalar o PHP, vamos precisar dele para o phpMyAdmin.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2 php5 libapache2-mod-php5 apache2-prefork-dev libapr1-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> passenger-install-apache2-module</pre></td></tr></table></div>

<p><strong>Agora nós precisamos configurar o Apache para carregar o módulo do Passenger:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>mods-enabled<span style="color: #000000; font-weight: bold;">/</span>passenger.load</pre></div></div>

<p>Adicione as seguintes linhas no arquivo em branco:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LoadModule passenger_module <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.4<span style="color: #000000; font-weight: bold;">/</span>ext<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>mod_passenger.so
PassengerRoot <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.4
PassengerRuby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby1.8
RailsEnv development</pre></div></div>

<p>Salve o arquivo e feche o gedit.</p>
<p><strong>Reinicie o Apache para carregar o Passenger:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p><strong>Instalando o MySQL:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server libmysql-ruby php5-mysql
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> phpmyadmin</pre></td></tr></table></div>

<p><strong>Configurando acesso a sua aplicação Ruby on Rails:</strong></p>
<p>Digamos que você tenha o código da sua aplicação Ruby on Rails no diretório:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>patrick<span style="color:#006600; font-weight:bold;">/</span>projetos<span style="color:#006600; font-weight:bold;">/</span>minha_aplicacao</pre></div></div>

<p>Vamos configurar para que quando você digitar no navegador <a href="http://minha_aplicacao">http://minha_aplicacao</a> você veja a sua aplicação em ambiente de desenvolvimento e possa interagir com ela.</p>
<p>Para isso, siga os passos abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p><strong>Vamos criar um novo host novo virtual host no Apache:</strong></p>

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

<p>No arquivo em branco adicione:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span>
ServerName minha_aplicacao
DocumentRoot <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>patrick<span style="color: #000000; font-weight: bold;">/</span>projetos<span style="color: #000000; font-weight: bold;">/</span>minha_aplicacao<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Salve e feche o gedit.</p>
<p>Vamos deixar esse virtual host disponível:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> ..<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>minha_aplicacao 001-minha_aplicacao</pre></td></tr></table></div>

<p>Agora vamos configurar para que quando você digitar no navegador <a href="http://minha_aplicacao">http://minha_aplicacao</a> o sistema operacional procure localmente ao invés de buscar na internet:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts</pre></div></div>

<p>Nesse arquivo adicione a linha:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">127.0.0.1	minha_aplicacao</pre></div></div>

<p>Logo abaixo da linha que começa com 127.0.1.1&#8230;<br />
Salve e feche o gedit.</p>
<p>Reinicie o Apache para carregar esse novo virtual host:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p><strong>Abra o navegador:</strong></p>
<p>Digite no browser <a href="http://minha_aplicacao">http://minha_aplicacao</a> e veja ela rodando.</p>
<p>Se você quiser usar o Vim como IDE de desenvolvimento Ruby on Rails leia esse post: <a href="http://blog.patrickespake.com/2009/04/21/usando-o-vim-para-programar-em-ruby-on-rails/">http://blog.patrickespake.com/2009/04/21/usando-o-vim-para-programar-em-ruby-on-rails/</a>.</p>
<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/06/25/ruby-on-rails-configurando-ambiente-de-desenvolvimento-no-linux/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails como colocar um captcha no formulário, instalação e uso do plugin Simple Captcha</title>
		<link>http://blog.patrickespake.com/2009/02/01/ruby-on-rails-como-colocar-um-captcha-no-formulario-instalacao-e-uso-do-plugin-simple-captcha/</link>
		<comments>http://blog.patrickespake.com/2009/02/01/ruby-on-rails-como-colocar-um-captcha-no-formulario-instalacao-e-uso-do-plugin-simple-captcha/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 18:21:27 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[actioncontroller]]></category>
		<category><![CDATA[applicationcontroller]]></category>
		<category><![CDATA[apply_simple_captcha]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[db:migrate]]></category>
		<category><![CDATA[expressica]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[formulário]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[instalação]]></category>
		<category><![CDATA[map.simple_captcha]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rubyforce]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[save_with_captcha]]></category>
		<category><![CDATA[show_simple_captcha]]></category>
		<category><![CDATA[simple catpcha]]></category>
		<category><![CDATA[simple_captcha]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[uso]]></category>
		<category><![CDATA[validate captcha]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=421</guid>
		<description><![CDATA[Conheço um plugin chamado Simple Captcha, eu acho ele muito bom e satifaz todas as minhas necessidades. Vou explicar como instalar e usar: Instalação ImageMagick e RMagick:: Como o captcha trabalha com geração dinâmica de imagens e necessário instalar essas libs: 1 2 3 sudo apt-get install imagemagick sudo apt-get install libmagick9-dev sudo gem install [...]]]></description>
			<content:encoded><![CDATA[<p>Conheço um plugin chamado <strong>Simple Captcha</strong>, eu acho ele muito bom e satifaz todas as minhas necessidades.</p>
<p>Vou explicar como instalar e usar:</p>
<p><strong>Instalação ImageMagick e RMagick:</strong>:</p>
<p>Como o captcha trabalha com geração dinâmica de imagens e necessário instalar essas libs:</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;">sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install imagemagick
sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install libmagick9<span style="color:#006600; font-weight:bold;">-</span>dev
sudo gem install rmagick</pre></td></tr></table></div>

<p><strong>Instalação do plugin Simple Captcha:</strong></p>
<p>No diretório do projeto digite 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;">ruby script<span style="color:#006600; font-weight:bold;">/</span>plugin install svn:<span style="color:#006600; font-weight:bold;">//</span>rubyforge.<span style="color:#9900CC;">org</span><span style="color:#006600; font-weight:bold;">/</span>var<span style="color:#006600; font-weight:bold;">/</span>svn<span style="color:#006600; font-weight:bold;">/</span>expressica<span style="color:#006600; font-weight:bold;">/</span>plugins<span style="color:#006600; font-weight:bold;">/</span>simple_captcha</pre></td></tr></table></div>

<p><strong>Configuração da aplicação:</strong></p>
<p>No diretório do projeto digite:</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;">rake simple_captcha:setup</pre></td></tr></table></div>

<p>O comando acima irá criar um arquivo de migração para armazenar os captchas gerados no banco de dados, também irá criar um partial para exibir o captcha na view.</p>
<p>Agora faça o migrate:</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;">rake db:migrate</pre></td></tr></table></div>

<p>É necessário adicionar uma rota no arquivo <strong>config/routes.rb</strong>, essa rota será responsável por gerar as imagens:</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;">simple_captcha</span> <span style="color:#996600;">'/simple_captcha/:action'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'simple_captcha'</span></pre></td></tr></table></div>

<p>Adicione a seguinte linha no arquivo <strong>app/controllers/application.rb</strong>:</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;">ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">SimpleCaptcha::ControllerHelpers</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p><strong>Como usar:</strong></p>
<p>No seu formulário na view adicione 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:#006600; font-weight:bold;">&lt;%</span>= show_simple_captcha<span style="color:#006600; font-weight:bold;">&#40;</span> : object<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;user&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>Onde <strong>: object =&gt; &#8220;user&#8221;</strong> é o nome do seu model.<br />
<strong>Obs.: Eu deixei separado o dois pontos, : object =&gt; &#8220;user&#8221; porque o wordpress troca por desenhos smiley, na hora de codificar deixa tudo junto.</strong></p>
<p>No model adicione a seguinte linha:</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;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  apply_simple_captcha
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Agora no controller ao invés de usar:</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;">@user</span>.<span style="color:#9900CC;">save</span></pre></td></tr></table></div>

<p>Use:</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;">@user</span>.<span style="color:#9900CC;">save_with_captcha</span></pre></td></tr></table></div>

<p>O método <strong>@user.save</strong> funciona corretamente, mas não leva em consideração o novo campo captcha, por isso é necessário usar o método <strong>@user.save_with_captcha</strong>.</p>
<p>Outras opções de uso e configuração, para ver outras alternativas eu sugiro que leia: <a href="http://expressica.com/simple_captcha/">http://expressica.com/simple_captcha/</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 alt="Recommend Me" src="http://workingwithrails.com/images/tools/compact-small-button.jpg" /></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/01/ruby-on-rails-como-colocar-um-captcha-no-formulario-instalacao-e-uso-do-plugin-simple-captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Como instalar a gem rmagick no Ubuntu</title>
		<link>http://blog.patrickespake.com/2009/02/01/como-instalar-a-gem-rmagick-no-ubuntu/</link>
		<comments>http://blog.patrickespake.com/2009/02/01/como-instalar-a-gem-rmagick-no-ubuntu/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 17:34:50 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[instalar]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[lib]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[sudo]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=419</guid>
		<description><![CDATA[Para instalar a gem rmagick no Ubuntu faça o seguinte: Instale o imagemagick: 1 sudo apt-get install imagemagick Instale a lib dev do imagemagick: 1 sudo apt-get install libmagick9-dev Finalmente instale a gem rmagick: 1 sudo gem install rmagick Se você gostou desse texto e acha que ajudou você, me recomende: .]]></description>
			<content:encoded><![CDATA[<p>Para instalar a gem rmagick no Ubuntu faça o seguinte:</p>
<p>Instale o imagemagick:</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;">sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install imagemagick</pre></td></tr></table></div>

<p>Instale a lib dev do imagemagick:</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;">sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install libmagick9<span style="color:#006600; font-weight:bold;">-</span>dev</pre></td></tr></table></div>

<p>Finalmente instale a gem rmagick:</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;">sudo gem install rmagick</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 alt="Recommend Me" src="http://workingwithrails.com/images/tools/compact-small-button.jpg" /></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/01/como-instalar-a-gem-rmagick-no-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instalando e usando o plugin paperClip no Ruby on Rails</title>
		<link>http://blog.patrickespake.com/2008/12/18/instalando-e-usando-o-plugin-paperclip-no-ruby-on-rails/</link>
		<comments>http://blog.patrickespake.com/2008/12/18/instalando-e-usando-o-plugin-paperclip-no-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 02:18:48 +0000</pubDate>
		<dc:creator>patrickespake</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Active Record]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[file_field]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[fotos]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[has_attached_file]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[imagens]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[image_content_type]]></category>
		<category><![CDATA[image_file_name]]></category>
		<category><![CDATA[image_file_size]]></category>
		<category><![CDATA[image_updated_at]]></category>
		<category><![CDATA[instalação]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[multipart]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sourcecode]]></category>
		<category><![CDATA[styles]]></category>
		<category><![CDATA[tarballs]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[thoughtbot]]></category>
		<category><![CDATA[tournaments]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[validates_attachment_content_type]]></category>

		<guid isPermaLink="false">http://patrickespake.wordpress.com/?p=305</guid>
		<description><![CDATA[O plugin paperClip do Ruby on Rails é muito bacana, agiliza muito a vida, com ele é possível fazer upload de imagens e já gerar várias dimensões da imagem. Vou explicar como instalar e como usar. Instalação: Faça o download do paperClip: http://github.com/tarballs/thoughtbot-paperclip-18c0246c11c51dafa77b6367ddaf730684d0e752.zip Descompacte o arquivo e renomei o diretório extraído para paperclip. Coloque esse [...]]]></description>
			<content:encoded><![CDATA[<p>O plugin paperClip do Ruby on Rails é muito bacana, agiliza muito a vida, com ele é possível fazer upload de imagens e já gerar várias dimensões da imagem.</p>
<p>Vou explicar como instalar e como usar.</p>
<p><strong>Instalação:</strong></p>
<p>Faça o download do paperClip: <a href="http://github.com/tarballs/thoughtbot-paperclip-18c0246c11c51dafa77b6367ddaf730684d0e752.zip">http://github.com/tarballs/thoughtbot-paperclip-18c0246c11c51dafa77b6367ddaf730684d0e752.zip</a></p>
<p>Descompacte o arquivo e renomei o diretório extraído para paperclip.</p>
<p>Coloque esse diretório dentro de <strong>seu_projeto/vendor/plugins/paperclip</strong>.</p>
<p>Você vai precisar do imageMagick, através dele o paperClip faz o resize nas imagens. Para instalar no Ubuntu 8.04 faça:</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;">sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install imagemagick</pre></td></tr></table></div>

<p><strong>Configuração:</strong></p>
<p>Para o paperClip funcionar você vai precisar que exista 4 novas colunas na sua tabela são elas: image_file_name, image_content_type, image_file_size, image_updated_at.</p>
<p>Esse nome image_&#8230; pode ser qualquer outra coisa por exemplo: avatar_&#8230;, foto_&#8230;</p>
<p>Seguindo essa ideia você poderia ter um migrate mais ou menos 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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> CreateTournaments <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;">:tournaments</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:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:name</span>,               <span style="color:#ff3333; font-weight:bold;">:string</span>,    <span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">100</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:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:description</span>,        <span style="color:#ff3333; font-weight:bold;">:text</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;">true</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:image_file_name</span>,    <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:image_content_type</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:image_file_size</span>,    <span style="color:#ff3333; font-weight:bold;">:integer</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:image_updated_at</span>,   <span style="color:#ff3333; font-weight:bold;">:timestamp</span>
      t.<span style="color:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:is_active</span>,          <span style="color:#ff3333; font-weight:bold;">:boolean</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;">column</span> <span style="color:#ff3333; font-weight:bold;">:start_date</span>,         <span style="color:#ff3333; font-weight:bold;">:date</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:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:end_date</span>,           <span style="color:#ff3333; font-weight:bold;">:date</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:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:created_at</span>,         <span style="color:#ff3333; font-weight:bold;">:timestamp</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:#9900CC;">column</span> <span style="color:#ff3333; font-weight:bold;">:updated_at</span>,         <span style="color:#ff3333; font-weight:bold;">:timestamp</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:#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;">:tournaments</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 é necessário informar o seu model que existirá anexos e que formatos são aceitos:</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:#9966CC; font-weight:bold;">class</span> Tournament <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
                    <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:large <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'600x600&gt;'</span>, <span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'300x300&gt;'</span>, <span style="color:#ff3333; font-weight:bold;">:small</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'150x150&gt;'</span>, <span style="color:#ff3333; font-weight:bold;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'50x50&gt;'</span><span style="color:#006600; font-weight:bold;">&#125;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;:rails_root/public/images/:class/:id/:style_:basename.:extension&quot;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/images/:class/:id/:style_:basename.:extension&quot;</span>
&nbsp;
  validates_uniqueness_of <span style="color:#ff3333; font-weight:bold;">:name</span>
  validates_presence_of   <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:start_date</span>, <span style="color:#ff3333; font-weight:bold;">:end_date</span>
  validates_attachment_content_type <span style="color:#ff3333; font-weight:bold;">:image</span>, <span style="color:#ff3333; font-weight:bold;">:content_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'image/jpeg'</span>, <span style="color:#996600;">'image/png'</span>, <span style="color:#996600;">'image/gif'</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>O interessante da linha abaixo, é que posso definir todos os tamanhos de imagens que desejo gerar em cima da imagem original, nesse trecho de código eu também alterei o path de armazenamento das imagens, fiz as imagens ficarem no diretório public_html/images/tournaments/id_do_banco_de_dados/imagens_em_diversas_dimensões:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">  has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
                    <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:large <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'600x600&gt;'</span>, <span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'300x300&gt;'</span>, <span style="color:#ff3333; font-weight:bold;">:small</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'150x150&gt;'</span>, <span style="color:#ff3333; font-weight:bold;">:thumb</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'50x50&gt;'</span><span style="color:#006600; font-weight:bold;">&#125;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;:rails_root/public/images/:class/:id/:style_:basename.:extension&quot;</span>,
                    <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/images/:class/:id/:style_:basename.:extension&quot;</span></pre></td></tr></table></div>

<p>A linha seguinte informa os tipos de mime types aceitos:</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;">  validates_attachment_content_type <span style="color:#ff3333; font-weight:bold;">:image</span>, <span style="color:#ff3333; font-weight:bold;">:content_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'image/jpeg'</span>, <span style="color:#996600;">'image/png'</span>, <span style="color:#996600;">'image/gif'</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<p>Agora você precisa definir que o seu formulário de cadastro trabalha com multipart, para enviar dados binários:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006600; font-weight:bold;">&lt;%</span> form_for <span style="color:#ff3333; font-weight:bold;">:tournament</span>, <span style="color:#0066ff; font-weight:bold;">@tournament</span>, <span style="color:#ff3333; font-weight:bold;">:url</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;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'create'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:html</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;">:multipart</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:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'form'</span>, <span style="color:#ff3333; font-weight:bold;">:locals</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;">:form</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> form <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    &lt;div class=&quot;submit&quot;&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= submit_tag <span style="color:#996600;">&quot;Criar&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/div&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></pre></td></tr></table></div>

<p>No código acima eu chamo o partial _form.rhtml, segue o seu conteúdo 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
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= error_messages_for <span style="color:#996600;">'tournament'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
&lt;!--[form:tournament]--&gt;
&lt;p&gt;&lt;label for=&quot;tournament_name&quot;&gt;Nome&lt;/label&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:name</span>  <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;tournament_description&quot;&gt;Descrição&lt;/label&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">text_area</span> <span style="color:#ff3333; font-weight:bold;">:description</span>  <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;tournament_image&quot;&gt;Imagem&lt;/label&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:image</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;tournament_is_active&quot;&gt;Ativo&lt;/label&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">check_box</span> <span style="color:#ff3333; font-weight:bold;">:is_active</span>  <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
&lt;p&gt;&lt;label for=&quot;tournament_start_date&quot;&gt;Data de início&lt;/label&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">date_select</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:start_date</span>, <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:day</span>, <span style="color:#ff3333; font-weight:bold;">:month</span>, <span style="color:#ff3333; font-weight:bold;">:year</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:use_month_numbers</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> <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&nbsp;
&lt;p&gt;&lt;label for=&quot;tournament_end_date&quot;&gt;Data de término&lt;/label&gt;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= form.<span style="color:#9900CC;">date_select</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:end_date</span>, <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:day</span>, <span style="color:#ff3333; font-weight:bold;">:month</span>, <span style="color:#ff3333; font-weight:bold;">:year</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:use_month_numbers</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>  <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/p&gt;
&lt;!--[eoform:tournament]--&gt;</pre></td></tr></table></div>

<p>Nesse partial _form.rhtml é declarado o campo para upload da imagem:</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>= form.<span style="color:#9900CC;">file_field</span> <span style="color:#ff3333; font-weight:bold;">:image</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Perceba que na tabela do banco de dados não existe a coluna chamada <strong>image</strong>, mas sim aquelas 4 que criei no migrate. Aqui que entra a mágica do paperClip juntamente com o model, ele consegue fazer o upload da imagem e definir os valores para os 4 campos no model.</p>
<p>Para exibir as imagens e suas diversas proporções use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag <span style="color:#0066ff; font-weight:bold;">@tournament</span>.<span style="color:#9900CC;">image</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>
<span style="color:#006600; font-weight:bold;">&lt;%</span>= image_tag <span style="color:#0066ff; font-weight:bold;">@tournament</span>.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:small</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>= image_tag <span style="color:#0066ff; font-weight:bold;">@tournament</span>.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:medium</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>= image_tag <span style="color:#0066ff; font-weight:bold;">@tournament</span>.<span style="color:#9900CC;">image</span>.<span style="color:#9900CC;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:large</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>Pronto! Depois de pegar o jeito com o paperClip você vai dar risada a toa. ;-)</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 alt="Recommend Me" src="http://workingwithrails.com/images/tools/compact-small-button.jpg" /></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/2008/12/18/instalando-e-usando-o-plugin-paperclip-no-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
