<?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>def Tenako.blog () end &#187; rails error login</title>
	<atom:link href="http://blog.tenako.com/tag/rails-error-login/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tenako.com</link>
	<description></description>
	<lastBuildDate>Sun, 10 Jul 2011 10:15:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Rails: Errores al instalar login_generator (1.2.2) en Rails 2.1.0</title>
		<link>http://blog.tenako.com/2008/10/09/rails-errores-al-instalar-login_generator-122/</link>
		<comments>http://blog.tenako.com/2008/10/09/rails-errores-al-instalar-login_generator-122/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 17:07:41 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails error login]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=16</guid>
		<description><![CDATA[Si queremos utilizar el gem (o es &#8220;la&#8221; gem, no tengo muy claro el genero) en rails 2.1.0 nos vamos a encontrar con lo siguientes problemas tras haberlo instalado: Primer problema,cuando vamos a generar nuestro sistema de login.La extension de las plantillas nos causa el primer problemilla: madtrick$ ruby script/generate login account create lib/login_system.rb create [...]]]></description>
			<content:encoded><![CDATA[<p>Si queremos  utilizar el gem (o es &#8220;la&#8221; gem, no tengo muy claro el genero) en rails 2.1.0 nos vamos a encontrar con lo siguientes problemas tras haberlo instalado:</p>
<p>Primer problema,cuando vamos a generar nuestro sistema de login.La extension de las plantillas nos causa el primer problemilla:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">madtrick$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate <span style="color: #c20cb9; font-weight: bold;">login</span> account
      create  lib<span style="color: #000000; font-weight: bold;">/</span>login_system.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>account_controller.rb
      create  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>account_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>account_helper.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>scaffold.rhtml
No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory - <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<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>rails-2.1.0<span style="color: #000000; font-weight: bold;">/</span> 
lib<span style="color: #000000; font-weight: bold;">/</span>rails_generator<span style="color: #000000; font-weight: bold;">/</span>generators<span style="color: #000000; font-weight: bold;">/</span>components<span style="color: #000000; font-weight: bold;">/</span>scaffold<span style="color: #000000; font-weight: bold;">/</span>templates<span style="color: #000000; font-weight: bold;">/</span>layout.rhtml</pre></div></div>

<p>El error deriva de que el script que genera el login sigue considerando que las plantillas tienen extension .rhtml, cuando eso ya no es asi.Ahora las plantillas utilizan la extension .html.erb</p>
<p>Por lo tanto para solucionar este problema lo que debemos de hacer es modificar la extension del fichero solicitado en el generador , login_generator.rb en este caso.</p>
<blockquote><p>En mi caso el fichero login_generator.rb se encuentra en <strong>/opt/local/lib/ruby/gems/1.8/gems/login_generator-1.2.2</strong> en otros sistemas puede que sea <strong>/usr/local/lib/ruby/gems/1.8/gems/login_generator-1.2.2</strong> o <strong>/ruby/local/lib/ruby/gems/1.8/gems/login_generator-1.2.2</strong></p></blockquote>
<p>Pasaremos de:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>17
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">m.<span style="color:#9900CC;">template</span> <span style="color:#996600;">&quot;scaffold:layout.rhtml&quot;</span>, <span style="color:#996600;">&quot;app/views/layouts/scaffold.rhtml&quot;</span></pre></td></tr></table></div>

<p>A:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>17
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">m.<span style="color:#9900CC;">template</span> <span style="color:#996600;">&quot;scaffold:layout.html.erb&quot;</span>, <span style="color:#996600;">&quot;app/views/layouts/scaffold.rhtml&quot;</span></pre></td></tr></table></div>

<p>Si ahora volvemos a intentar generar el sistema de login no tendremos ningun problema:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">madtrick$ ruby script<span style="color: #000000; font-weight: bold;">/</span>generate <span style="color: #c20cb9; font-weight: bold;">login</span> account
   identical  lib<span style="color: #000000; font-weight: bold;">/</span>login_system.rb
   identical  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>account_controller.rb
   identical  test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>account_controller_test.rb
   identical  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>account_helper.rb
overwrite app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>scaffold.rhtml? \ 
 <span style="color: #7a0874; font-weight: bold;">&#40;</span>enter <span style="color: #ff0000;">&quot;h&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Ynaqdh<span style="color: #7a0874; font-weight: bold;">&#93;</span> Y
       force  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>layouts<span style="color: #000000; font-weight: bold;">/</span>scaffold.rhtml
      create  public<span style="color: #000000; font-weight: bold;">/</span>stylesheets<span style="color: #000000; font-weight: bold;">/</span>scaffold.css
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>account
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>account<span style="color: #000000; font-weight: bold;">/</span>welcome.rhtml
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>account<span style="color: #000000; font-weight: bold;">/</span>login.rhtml
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>account<span style="color: #000000; font-weight: bold;">/</span>logout.rhtml
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>account<span style="color: #000000; font-weight: bold;">/</span>signup.rhtml
      create  README_LOGIN</pre></div></div>

<p>Segundo problema.Tras solventar lo anterior, estamos ansiosos por probar nuestro sistema de login asi que vamos a nuestro navegador y tecleamos: <a href="http://localhost:3000/account/login" onclick="javascript:pageTracker._trackPageview('/outbound/article/localhost:3000');">http://localhost:3000/account/login</a></p>
<blockquote><p>En la anterior direccion asumimos lo siguiente:</p>
<ul>
<li>Que el controlador que hemos creado para gestionar las funciones de login tiene por nombre AccountController </li>
<li>Que tenemos una ruta en routes.rb  que funciona para esta peticion</li>
</ul>
</blockquote>
<p>Si probamos esto una bonita pantalla de error nos dara la bienvenida:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ArgumentError <span style="color: #000000; font-weight: bold;">in</span> AccountController<span style="color: #666666; font-style: italic;">#login</span>
&nbsp;
wrong number of arguments <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Bien, para solucionar esto debemos de modificar todos los @request.method que nos encontremos en nuestro controlador por @request.<a href="http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html#M000787" onclick="javascript:pageTracker._trackPageview('/outbound/article/api.rubyonrails.org');">request_method</a> para evitar colisiones con la palabra reservada de ruby <a href="http://www.ruby-doc.org/core/classes/Object.html#M000338" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.ruby-doc.org');">method</a></p>
<p>Tras solucionar esto volvemos a probar nuestro sistema de login, pero un vez mas nos la dan con queso:</p>
<p>Segundo problema,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> NoMethodError <span style="color: #000000; font-weight: bold;">in</span> AccountController<span style="color: #666666; font-style: italic;">#login</span>
&nbsp;
You have a nil object when you didn<span style="color: #ff0000;">'t expect it!
The error occurred while evaluating nil.request_method</span></pre></div></div>

<p>Bien, bien.Veamos que pasa aqui.Como podemos observar el mensaje de error nos dice que el error ocurrio al tratar de evaluar <strong>nil</strong>.request_method.Pero oiga, como que nil!! Si yo estoy viendo @request.request_method.</p>
<p>Lo que pasa aqui es que en esta version de <a href="http://www.rubyonrails.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.rubyonrails.org');">Rails</a>, <strong>@request</strong> (al igual que <strong>@params</strong>, <strong>@session</strong>, <strong>@flash</strong>, <strong>@cookies</strong>, <strong>@headers</strong>, <strong>@response</strong>) ha quedado en desuso en favor de los &#8220;accessor methods&#8221; que tienen el mismo nombre que las variables pero sin la arroba.Es decir donde tenemos @request.request_method pasamos a tener request.request_method y asi sucesivamente.</p>
<p>Probamos los cambios y nos encontramos con el tercer problema:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> NoMethodError <span style="color: #000000; font-weight: bold;">in</span> Account<span style="color: #666666; font-style: italic;">#login</span>
&nbsp;
Showing account<span style="color: #000000; font-weight: bold;">/</span>login.rhtml where line <span style="color: #666666; font-style: italic;">#1 raised:</span>
&nbsp;
undefined method <span style="color: #000000; font-weight: bold;">`</span>start_form_tag<span style="color: #ff0000;">' for #&lt;ActionView::Base:0x35a61dc&gt;</span></pre></div></div>

<p>login.rhtml luce de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%%</span>= start_form_tag <span style="color:#ff3333; font-weight:bold;">:action</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;login&quot;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
...
<span style="color:#006600; font-weight:bold;">&lt;%%</span>= end_form_tag <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>start_form_tag, tambien esta en desuso, en su lugar debemos de utilizar <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001699" onclick="javascript:pageTracker._trackPageview('/outbound/article/api.rubyonrails.org');">form_tag</a>.De esta forma login.rhtml nos queda de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_tag <span style="color:#996600;">'/account/login'</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> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Ahora por lo menos podemos probar nuestro login.Lo probamos y tras hacer click en el boton de login,nos encontramos con el cuarto error,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> NoMethodError <span style="color: #000000; font-weight: bold;">in</span> AccountController<span style="color: #666666; font-style: italic;">#login</span>
&nbsp;
undefined method <span style="color: #000000; font-weight: bold;">`</span>find_first<span style="color: #ff0000;">' for #&lt;Class:0x365c8b0&gt;</span></pre></div></div>

<p>find_first es otro de los metodos en desuso.Debemos de cambiarlo por <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001298" onclick="javascript:pageTracker._trackPageview('/outbound/article/api.rubyonrails.org');">find</a>, con el simbolo :first como primer parametro y la opcion :conditions con la condicion que teniamos en find_first.</p>
<p>Es decir, pasamos de:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">find_first<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;login = ? AND password = ?&quot;</span>, login, sha1<span style="color:#006600; font-weight:bold;">&#40;</span>pass<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>A:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:first</span>,:conditions<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;login = ? AND password = ?&quot;</span>, login, sha1<span style="color:#006600; font-weight:bold;">&#40;</span>pass<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Si volvemos a probar, adivinad que pasa&#8230;.si, otro error.Por el quinto vamos,otra vez por elementos en desuso.En este caso se trata de la variable @session residente en el fichero login_system.rb.Cambiamos esta y las demas variables existentes en dicho fichero a sus &#8220;accesor methods&#8221; , guardamos y volvemos a probar&#8230; e-voilà!!</p>
<p>Funciona!!</p>
<p>Espero que todo este rollo le sea de ayuda a alguien : )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2008/10/09/rails-errores-al-instalar-login_generator-122/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

