<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>rails-edge &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/rails-edge/</link>
	<description>Feed of posts on WordPress.com tagged "rails-edge"</description>
	<pubDate>Sat, 05 Dec 2009 09:35:00 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Rails edge, Ruby 1.9 style String interpolation support ]]></title>
<link>http://gastonramos.wordpress.com/2009/07/10/rails-edge-ruby-1-9-style-string-interpolation-support/</link>
<pubDate>Fri, 10 Jul 2009 18:04:00 +0000</pubDate>
<dc:creator>Gastón Ramos</dc:creator>
<guid>http://gastonramos.wordpress.com/2009/07/10/rails-edge-ruby-1-9-style-string-interpolation-support/</guid>
<description><![CDATA[Este es el primer post de una serie que he decidido comenzar titulada &#8220;Analizando commits de r]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Este es el primer post de una serie que he decidido comenzar titulada <strong>&#8220;Analizando commits de rails edge&#8221;</strong>. Aclaro que los post no van a tener orden alguno y que voy a comentar los que me llaman la atención a _mí_ <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
En este caso el <a href="http://github.com/rails/rails/commit/da635394c1c3004f4dacf4a35275404e5b1aef43">commit</a> se trata de agregar a rails la nueva forma de interpolación de strings que trae ruby 1.9 ( la idea es que se pueda usar con versiones menores también), pueden ver el código en este archivo:</p>
<pre>
activesupport/lib/active_support/core_ext/string/interpolation.rb
</pre>
<p>Cómo uds sabrán en Ruby se pueden interpolar strings de la siguiente manera:</p>
<pre>
&#62;&#62;"%s, %s" % ["Masao", "Mutoh"]
=&#62; "Masao, Mutoh"
</pre>
<p>Cómo lo explica el comentario en el código:</p>
<pre>
 # call-seq:
  #   %(arg)
  #   %(hash)
  #
  # Format - Uses str as a format specification, and returns the result of applying it to arg.
  # If the format specification contains more than one substitution, then arg must be
  # an Array containing the values to be substituted. See Kernel::sprintf for details of the
  # format string. This is the default behavior of the String class.
  #   * arg: an Array or other class except Hash.
  #   * Returns: formatted String
  # Example:
  #    "%s, %s" % ["Masao", "Mutoh"]
  #
  # Also you can use a Hash as the "named argument". This is recommended way so translators
  # can understand the meanings of the msgids easily.
  #   * hash: {:key1 =&#62; value1, :key2 =&#62; value2, ... }
  #   * Returns: formatted String
  # Example:
  #   For strings.
  #   "%{firstname}, %{familyname}" % {:firstname =&#62; "Masao", :familyname =&#62; "Mutoh"}
  #
  #   With field type to specify format such as d(decimal), f(float),...
  #   "%d, %.1f" % {:age =&#62; 10, :weight =&#62; 43.4}
</pre>
<p>Es decir que ahora podemos interpolar strings de la siguiente manera:</p>
<pre>
&#62;&#62; "%{firstname}, %{familyname}" % {:firstname =&#62; "Masao", :familyname =&#62; "Mutoh"}
ArgumentError: malformed format string - %{
	from (irb):2:in `%'
	from (irb):2
&#62;&#62;
</pre>
<p>Auuuchh! estoy probando con un irb con ruby 1.8.6, así que necesito requerir el archivo:</p>
<pre>
&#62;&#62; require 'activesupport/lib/active_support/core_ext/string/interpolation.rb'
=&#62; true
&#62;&#62; "%{firstname}, %{familyname}" % {:firstname =&#62; "Masao", :familyname =&#62; "Mutoh"}
=&#62; "Masao, Mutoh"
</pre>
<p>Ahora sí! podemos interpolar string nombrados pasando un hash como argumento, Hermoso!<br />
Estuve mirando en los fuentes de Ruby 1.9 y no encuentro dónde está escrita esta nueva funcionalidad, el método que define la interpolación con&#8221;%&#8221; es  <strong>rb_str_format_m</strong> y está en la línea número 1202 del archivo <strong>string.c</strong> en el trunk de ruby, pero sólo está la vieja forma de interpolación. <strong>Entonces dónde está ? Alguien sabe?</strong><br />
Es más hice esta prueba:</p>
<pre>
$ irb1.9
require 'activesupport/lib/active_support/string/interpolation.rb'
=&#62; true
irb(main):002:0&#62; "%{firstname}, %{familyname}" % {:firstname =&#62; "Masao", :familyname =&#62; "Mutoh"}
ArgumentError: malformed format string - %{
	from (irb):2:in `%'
	from (irb):2
	from /usr/bin/irb1.9:12:in `'
</pre>
<p>Y la versión que tengo de ruby 1.9 es:<br />
<strong>ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux]</strong><br />
Un poco vieja, probemos con ruby 1.9 compilado desde trunk<br />
<strong>ruby 1.9.2dev (2009-07-11 trunk 24027) [i686-linux]</strong></p>
<pre>
./ruby  -e 'puts "%{firstname}, %{familyname}" % {:firstname =&#62; "Masao", :familyname =&#62; "Mutoh"}'
Masao, Mutoh
</pre>
<p>Funcionó! entonces en algún lugar tiene que estar.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Nested Forms rails 2.3]]></title>
<link>http://gastonramos.wordpress.com/2009/02/18/nested-forms-rails-23/</link>
<pubDate>Wed, 18 Feb 2009 15:22:30 +0000</pubDate>
<dc:creator>Gastón Ramos</dc:creator>
<guid>http://gastonramos.wordpress.com/2009/02/18/nested-forms-rails-23/</guid>
<description><![CDATA[En el proyecto en el que estoy actualemente estamos usando Rails 2.3, uno de los motivos de usar rai]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>En el proyecto en el que estoy actualemente estamos usando Rails 2.3, uno de los motivos de usar rails 2.3 es que nos venía muy bien la nueva feature &#8220;<strong>Nested Forms&#8221;</strong>, resultaque estuve dando vueltas con algunos problemas hasta que finalmente los saque funcionando bien.</p>
<p>Les cuento yo tengo un formulario para crear un user, el modelo de user es el siguiente:</p>
<pre>class User &#60; ActiveRecord::Base
   has_one :person, :as =&#62; :personable, :dependent =&#62; :destroy
   accepts_nested_attributes_for :person
....
end</pre>
<p>Es decir que un user tiene datos de contacto a travez de has_one :person (suena raro creo que se podría cambiar por has_one :contact_info, :class_name =&#62; &#8220;Person&#8221;) , y entonces el form era el siguiente:</p>
<pre>&#60;% form_for(:user, :url =&#62; users_path) do &#124;f&#124; -%&#62;

&#60;p&#62;&#60;%= label_tag 'login' %&#62;&#60;br/&#62;
&#60;%= f.text_field :login %&#62;&#60;/p&#62;

&#60;p&#62;&#60;%= label_tag 'password' %&#62;&#60;br/&#62;
&#60;%= f.password_field :password %&#62;&#60;/p&#62;

&#60;p&#62;&#60;%= label_tag 'password_confirmation', 'Confirm Password' %&#62;&#60;br/&#62;
&#60;%= f.password_field :password_confirmation %&#62;&#60;/p&#62;

&#60;% f.fields_for(:person) do &#124;person_fields&#124; %&#62;
  &#60;p&#62;&#60;%= person_fields.label :email %&#62;&#60;br/&#62;
  &#60;%= person_fields.text_field :email %&#62;&#60;/p&#62;

  &#60;p&#62;&#60;%= person_fields.label :first_name, 'First Name:' %&#62;&#60;br/&#62;
  &#60;%= person_fields.text_field :first_name %&#62;&#60;/p&#62;
&#60;% end %&#62;

&#60;p&#62;&#60;%= submit_tag 'Create User' %&#62;&#60;/p&#62;

&#60;% end -%&#62;</pre>
<p>Resulta que esto no me funcionó y me daba el siguiente error:</p>
<p>ActiveRecord::AssociationTypeMismatch (Person(#-619527948) expected, got HashWithIndifferentAccess(#-607513158)):</p>
<p>El problema puntual era que no generaba bien el form y en vez de generar esto:</p>
<pre>&#60;<span class="start-tag">input</span><span class="attribute-name"> id</span>=<span class="attribute-value">"user_person_attributes_first_name"
  </span><span class="attribute-name">name</span>=<span class="attribute-value">"user[person_attributes][first_name]" </span><span class="attribute-name">
  size</span>=<span class="attribute-value">"30" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text" </span><span class="error"><span class="attribute-name">/</span></span>&#62;</pre>
<p>generaba esto:</p>
<pre>&#60;<span class="start-tag">input</span><span class="attribute-name"> id</span>=<span class="attribute-value">"user_person_first_name"
  </span><span class="attribute-name">name</span>=<span class="attribute-value">"user[person][first_name]" </span><span class="attribute-name">
  size</span>=<span class="attribute-value">"30" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text" </span><span class="error"><span class="attribute-name">/</span></span>&#62;</pre>
<p>Y entonces daba el error por que ActiveRecord (Nested model) genera un método <strong>person_attributes=</strong> en modelo dónde declaramos el accepts_nested_attributes_for (user en este caso) y por eso el form anterior no funciona como era de esperar.</p>
<p>En el controller tenía lo siguiente:</p>
<pre>class UsersController &#60; ApplicationController
  def new
    @user = User.new(:person =&#62; Person.new)
  end

  def create
    @user = User.new(params[:user])
    @user.save
  end
.....
end</pre>
<p>La solución fue modificar el form y hacer así:</p>
<pre>&#60;% form_for @user do &#124;f&#124; -%&#62;

&#60;p&#62;&#60;%= label_tag 'login' %&#62;&#60;br/&#62;
&#60;%= f.text_field :login %&#62;&#60;/p&#62;

&#60;p&#62;&#60;%= label_tag 'password' %&#62;&#60;br/&#62;
&#60;%= f.password_field :password %&#62;&#60;/p&#62;

&#60;p&#62;&#60;%= label_tag 'password_confirmation', 'Confirm Password' %&#62;&#60;br/&#62;
&#60;%= f.password_field :password_confirmation %&#62;&#60;/p&#62;

&#60;% f.fields_for(:person) do &#124;person_fields&#124; %&#62;
  &#60;p&#62;&#60;%= person_fields.label :email %&#62;&#60;br/&#62;
  &#60;%= person_fields.text_field :email %&#62;&#60;/p&#62;

  &#60;p&#62;&#60;%= person_fields.label :first_name, 'First Name:' %&#62;&#60;br/&#62;
  &#60;%= person_fields.text_field :first_name %&#62;&#60;/p&#62;
&#60;% end %&#62;

&#60;p&#62;&#60;%= submit_tag 'Create User' %&#62;&#60;/p&#62;

&#60;% end -%&#62;</pre>
<p>cambié el</p>
<pre>&#60;% form_for(:user, :url =&#62; users_path) do &#124;f&#124; -%&#62;</pre>
<p>por</p>
<pre>&#60;% form_for @user do &#124;f&#124; -%&#62;</pre>
<p>El form para editar un user quedó prácticamente igual y funciona con los attributes de person y todo sin hacer nada del lado del controller. Ahora la pregunta es: Esta bien que nested_forms solamente funcione con la forma?:</p>
<pre>&#60;% form_for @user do &#124;f&#124; -%&#62; </pre>
<p>S<strong>i alguien tiene la respuesta que comente!</strong></p>
<p>Saludos</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Rails agrega soporte para "shallow nested routes"]]></title>
<link>http://gastonramos.wordpress.com/2008/09/05/rails-agrega-soporte-para-shallow-nested-routes/</link>
<pubDate>Fri, 05 Sep 2008 15:06:17 +0000</pubDate>
<dc:creator>Gastón Ramos</dc:creator>
<guid>http://gastonramos.wordpress.com/2008/09/05/rails-agrega-soporte-para-shallow-nested-routes/</guid>
<description><![CDATA[Muchas veces cuando tenemos recursos anidados nos encontramos definiendo un map.resource (o una ruta]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Muchas veces cuando tenemos recursos anidados nos encontramos definiendo un map.resource (o una ruta) adicional para acceder al mismo recurso pero sin la anidación. Para referenciar a un miembro específico de este sin el prefijo del padre sin tener que definir otra ruta, Rails edge agrega una opción a map.resource para lograr esto.</p>
<p><strong>Ejemplo:</strong></p>
<pre>
map.resources :users, :shallow =&#62; true do &#124;user&#124;
  user.resources :posts
end
</pre>
<p>* GET /users/1/posts (mapea a la acción PostsController#index action como siempre)<br />
      se agrega la ruta nombrada &#8220;user_posts&#8221; como siempre.</p>
<p><strong>Lo nuevo:</strong></p>
<p>* GET /posts/2 (mapea a la acción PostsController#show como si no sería anidada)<br />
      Adicionalmente, se agrega también la ruta nombrada &#8220;post&#8221;.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Rails edge: Nuevo método Enumerable#many?]]></title>
<link>http://gastonramos.wordpress.com/2008/06/13/rails-edge-nuevo-metodo-enumerablemany/</link>
<pubDate>Sat, 14 Jun 2008 01:47:11 +0000</pubDate>
<dc:creator>Gastón Ramos</dc:creator>
<guid>http://gastonramos.wordpress.com/2008/06/13/rails-edge-nuevo-metodo-enumerablemany/</guid>
<description><![CDATA[Rails agrega un nuevo método al módulo Enumerable. Vamos al código para explicar cómo funciona este ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Rails agrega un nuevo método al módulo  Enumerable.  Vamos al código para explicar cómo funciona este nuevo método:</p>
<pre>
&#62;&#62; Post.all.many?
=&#62; false
&#62;&#62; Post.create({:title =&#62; "hola", :post =&#62; "hola"})
&#62;&#62; Post.all.many?
=&#62; false
&#62;&#62; Post.create({:title =&#62; "otro hola", :post =&#62; "otro hola"})
&#62;&#62; Post.all.many?
=&#62; true
&#62;&#62; Post.all.size
=&#62; 2
&#62;&#62; posts = Post.find(:all, :conditions =&#62; {:post =&#62; "hola"})
&#62;&#62; posts.many?
=&#62; false
&#62;&#62; posts.size
=&#62; 1
</pre>
<p>La función de este nuevo método many? es básicamente encapsular collection.size &#62; 1, es un detalle bastante cómodo que opinan uds?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Edge Rails: Ruby On Rails 2.1 Vem ai]]></title>
<link>http://tchandy.wordpress.com/2008/05/26/edge-rails-ruby-on-rails-21-vem-ai/</link>
<pubDate>Mon, 26 May 2008 15:00:57 +0000</pubDate>
<dc:creator>tchandy</dc:creator>
<guid>http://tchandy.wordpress.com/2008/05/26/edge-rails-ruby-on-rails-21-vem-ai/</guid>
<description><![CDATA[Bom Dia, Logo está saindo o Ruby on Rails 2.1 (aka Edge)&#8230; o Primeiro Release já foi lançando, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Bom Dia,</p>
<p>Logo está saindo o Ruby on Rails 2.1 (aka Edge)&#8230; o Primeiro Release já foi lançando, e provavelmente a versão 2.1 vai ser lançando na <a href="http://en.oreilly.com/rails2008/public/content/home">RailsConf</a> que acontece nessa semana <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &#8230;</p>
<p>Para quem quiser ir se antecipando, pode dar uma olhada no blog do <a href="http://nomedojogo.com">Carlos Brando</a>, que é o melhor blog sobre rails edge em português na atualidade&#8230; Ele faz vários posts e comentários sobre as novas features&#8230;</p>
<p>Ou então, quem quiser dar uma olhada no primeiro tutorial completo sobre Rails Edge, pode dar uma olhada no blog do Fabio Akita, nos Seguintes Links:</p>
<p><a href="http://www.akitaonrails.com/2008/5/25/rolling-with-rails-2-1-the-first-full-tutorial-part-1">Parte 1<br />
</a></p>
<p><a href="http://www.akitaonrails.com/2008/5/26/rolling-with-rails-2-1-the-first-full-tutorial-part-2">Parte 2</a></p>
<p>Abraços</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[special Rails 2.0 features OR what impressed me most about Rails (2nd tranche of Rails links)]]></title>
<link>http://dagobart.wordpress.com/2008/03/21/special-rails-20-features-or-what-impressed-me-most-about-rails-2nd-tranche-of-rails-links/</link>
<pubDate>Fri, 21 Mar 2008 14:52:42 +0000</pubDate>
<dc:creator>dagobart</dc:creator>
<guid>http://dagobart.wordpress.com/2008/03/21/special-rails-20-features-or-what-impressed-me-most-about-rails-2nd-tranche-of-rails-links/</guid>
<description><![CDATA[Just after the turn of the year 2006&gt;2007 I dove into Ruby. My original project is related to sem]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Just after the turn of the year 2006&#62;2007 I dove into Ruby. My original project is related to semantics, and I had to deal with large directed graphs and complex data structures. I put programming-as-a-hobby aside, about 1997, and the then most-recent language I&#8217;ve been aware of was Perl. For doing the occasional programming task, that one was sufficient. For dealing with graphs it was not, despite it fulfilled the requirement to bring these graphs to the web one day. So I was looking for a new language. What I were aware of were PHP, Ruby/Rails and Python. For being as low-level as Pascal was, PHP quickly dropped off my sight. Next I had to decide whether to take Python &#8212; which was more well-known here in Europe back then &#8212; or Ruby, which was rather unknown here but by Rails featured a yet working framework for web development. Having learnt floods of newbies usually won&#8217;t need to be a higher quality in support (read: Windows-refugees in Ubuntu), I leaned towards Ruby. But on the other hand, Ruby was Japan-made and its community might be mostly non-English. Which might make it hard for me to get into that language at all. Nevertheless, I gave both a shot, then learned about a significance of white-space in Python, which made the difference. Anyways, I didn&#8217;t go into Rails back then.</p>
<p>Been on some kind of sabbatical for a while, I had a hard time to get into a job afterwards, so although not loving to program in Perl, I applied for a PHP job, which I am currently in. It&#8217;s even more that low-level Pascal way of approaching things than I imagined. Looking for an alternative against doing web development <em>that</em> low-level, I peeked into Rails. (You might have noticed <a href="http://dagobart.wordpress.com/2008/03/21/first-tranche-of-rails-links-recommended-readings-podcast-where-to-get-help/">my previous Ruby/Rails related posts</a>, so that you might confirm this. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) However, having done some research on Rails and were reading Rails&#8217; ActionConroller documentation (and of other classes ones too), I came across the explanation of session management in Rails. Having seen what a hassle it is in the Joomla! PHP CMS to deal with sessions, that mention raised my interest. I learned that there are at least three different ways to deal with session using Rails, until now: Store the data in a cache, in the database or a session cookie at the user&#8217;s place. But what impressed me most was to learn that Rails has built-in mechanisms to prevent &#8220;the user from tampering with the session&#8221;, but at the same time &#8220;allows him to see its <em>[i.e. the cookie's]</em> contents&#8221;: &#8220;Sessions are stored in a browser cookie that&#8217;s cryptographically signed, but unencrypted, by default&#8221;. (All quotes taken from Rails&#8217; ActionConroller documentation.)<br />
&#160;</p>
<p>More specific to dedicated Rails development, a while later I learned about Rails plugins (but <a href="http://twitter.com/dagobart/statuses/767246502">still haven&#8217;t figured out</a> what they are literally). However, who&#8217;s yet somewhat deeper in Rails development might gladly be using them, so for the Rails Edge blogger Ryan Daigle it was noteworthy to mention that <a href="http://ryandaigle.com/articles/2007/10/26/what-s-new-in-edge-rails-fixtures-just-got-a-whole-lot-easier">the Rathole plugin made it into Rails</a> &#8212; a Rails plugin that eases setting up database fixtures a rather lot. &#8212; For those who are not that deep in Rails he gives some nicely comprehensible examples. You&#8217;d see the elegance at once.</p>
<p>Anyways, if you&#8217;d like to get some deeper glance into Rails 2 <a href="http://dagobart.wordpress.com/2008/03/21/first-tranche-of-rails-links-recommended-readings-podcast-where-to-get-help/">I once again recommend you</a> to read Peter Marklund&#8217;s presentation on <a href="http://marklunds.com/s5/rails2-conventions.html">Building Web Apps with Rails 2</a>.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
