<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Plataformatec Blog</title>
	
	<link>http://blog.plataformatec.com.br</link>
	<description>Plataformatec's place to talk about Ruby, Ruby on Rails and software engineering</description>
	<lastBuildDate>Thu, 17 May 2012 21:58:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/PlataformaBlog" /><feedburner:info uri="plataformablog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>A praise for a hard, sweaty and great work done</title>
		<link>http://feedproxy.google.com/~r/PlataformaBlog/~3/6yHtVla8aaI/</link>
		<comments>http://blog.plataformatec.com.br/2012/05/a-praise-for-a-hard-sweaty-and-great-work-done/#comments</comments>
		<pubDate>Thu, 17 May 2012 21:38:06 +0000</pubDate>
		<dc:creator>Marcelo Park</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[culture]]></category>
		<category><![CDATA[great work]]></category>
		<category><![CDATA[plataformatec]]></category>
		<category><![CDATA[team]]></category>

		<guid isPermaLink="false">http://blog.plataformatec.com.br/?p=2728</guid>
		<description><![CDATA[Congratulations to our fellow Carlos Antonio (@cantoniodasilva) and Rafael França (@rafaelfranca) for honorably earning the commit access to the Ruby on Rails repository!]]></description>
			<content:encoded><![CDATA[<p>It is no secret that our team has a great passion for contributing to the open source community and once in a while we receive compliments &#8211; it is great to have our work recognized; thank you all for always being supportive. =D</p>
<p>We&#8217;d proudly like to announce that, due to their contributions, two specific members of our team were recently awarded by the Ruby on Rails community (by the Rails Core Team, to be more precise).</p>
<p>Without further ado we&#8217;d like to congratulate our fellow Carlos Antonio (<a href="http://twitter.com/cantoniodasilva">@cantoniodasilva</a>) and Rafael França (<a href="http://twitter.com/rafaelfranca">@rafaelfranca</a>) for honorably earning the commit access to the Ruby on Rails repository!</p>
<div id="attachment_2740" class="wp-caption aligncenter" style="width: 522px"><img class=" wp-image-2740 " title="@cantoniodasilva and @rafaelfranca" src="http://blog.plataformatec.com.br/wp-content/uploads/2012/05/Screen-shot-2012-05-018.jpg" alt="" width="512" height="257" /><p class="wp-caption-text">@cantoniodasilva and @rafaelfranca</p></div>
<p>Guys, congratulations! \o/</p>
<p>We are all very happy for this great achievement. Great work!<br />
From your friends at Plataformatec.</p>
<img src="http://feeds.feedburner.com/~r/PlataformaBlog/~4/6yHtVla8aaI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.plataformatec.com.br/2012/05/a-praise-for-a-hard-sweaty-and-great-work-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.plataformatec.com.br/2012/05/a-praise-for-a-hard-sweaty-and-great-work-done/</feedburner:origLink></item>
		<item>
		<title>Say hi to Devise 2.1.0 !</title>
		<link>http://feedproxy.google.com/~r/PlataformaBlog/~3/8K2W1EFlVRA/</link>
		<comments>http://blog.plataformatec.com.br/2012/05/say-hi-to-devise-2-1-0/#comments</comments>
		<pubDate>Tue, 15 May 2012 17:17:10 +0000</pubDate>
		<dc:creator>Rodrigo Flores</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[devise]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.plataformatec.com.br/?p=2527</guid>
		<description><![CDATA[In this blog post we talk about a new feature upcoming on Devise 2.1 that aims to provide developers faster feedback in case a model is missing a field required by Devise behaviors. ]]></description>
			<content:encoded><![CDATA[<p>After 4 months of our last major version release, we&#8217;re releasing Devise 2.1.0, which includes several bug fixes, some new features and the removal of features deprecated on Devise 2.0. If you&#8217;re eager to do the update, please check Devise&#8217;s wiki page about <a href="https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.1">Upgrading from 2.0 to 2.1</a>. You can also check the <a href="https://github.com/plataformatec/devise/blob/master/CHANGELOG.rdoc">changelog</a> or the <a href="https://github.com/plataformatec/devise/compare/v2.0.4...v2.1.0">commits between 2.0.4 and 2.1.0</a>.</p>
<h2>Encrytable is now a gem</h2>
<p>As it was only used for old encryption algorithms like sha1 or md5, we have extracted encryptable module to a separated ruby gem. So, if you&#8217;re using the encryptable module, you should only require it on your Gemfile and you&#8217;re good to go!</p>
<h2>Check fields</h2>
<p>To allow a developer to cherry-pick which features they want to add to their models, Devise splits its behaviors into modules. One of the consequences of such splitting is that you don&#8217;t know if the persistence layer provides all fields required by the behavior. For example, the database authenticatable module requires a <code>encrypted_password</code> field. If the field does not exist, you will end up getting an error during a request. Usually those fields are automatically added to the migration when you call the devise generator, but if you decide to include a module after, you can easily forget to add the new fields.</p>
<p>That said, in order to provide faster feedback, Devise now has a method that checks if a given class is missing any of the required fields and raises an error if so. You can call this method as follow (in case your Devise class is <code>User</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Devise::Models</span>.<span style="color:#9900CC;">check_fields</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>User<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>We&#8217;ve implemented this feature in an agnostic way, to not depend on a specific ORM, but only to verify if the instance responds to the required fields. So even if your ORM does everything through <code>method_missing</code>, you should be able to use this method (we&#8217;re relying that you also have implemented a working <code>respond_to?</code>, which is strongly recommendeded when using <code>method_missing</code>).</p>
<p>When <code>check_fields!</code> is called, Devise will detect the included modules in the given class and, if there is a missing attribute, it will raise a <code>Devise::Models::MissingAttribute</code> exception with a message telling you all required fields that doesn&#8217;t exist. You can easily use that method with your favorite test framework:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Devise::Models</span>.<span style="color:#9900CC;">check_fields</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>User<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>And then you will be able to check if your migrations have added the correct fields to your database.</p>
<h3>A message to module maintainers</h3>
<p>If you&#8217;re a maintainer of a Devise module, you should add a method to each of your modules called <code>self.required_fields(klass)</code> that returns an array of required fields. If the method is absent, you will get a deprecation warning.</p>
<p><strong>UPDATE</strong>: Fixed a class name and corrected a grammar error.</p>
<img src="http://feeds.feedburner.com/~r/PlataformaBlog/~4/8K2W1EFlVRA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.plataformatec.com.br/2012/05/say-hi-to-devise-2-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.plataformatec.com.br/2012/05/say-hi-to-devise-2-1-0/</feedburner:origLink></item>
		<item>
		<title>I18n Alchemy – localization and parsing</title>
		<link>http://feedproxy.google.com/~r/PlataformaBlog/~3/wJUlCUKSCWM/</link>
		<comments>http://blog.plataformatec.com.br/2012/05/i18n-alchemy-localization-and-parsing/#comments</comments>
		<pubDate>Tue, 08 May 2012 17:23:20 +0000</pubDate>
		<dc:creator>Carlos Antônio</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://blog.plataformatec.com.br/?p=2328</guid>
		<description><![CDATA[Today I want to show you a project I&#8217;ve started over a year ago, during Mendicant University core skills course. For those who don&#8217;t know, Mendicant University is a group of skilled software developers that offer courses, mentoring, and help out the community, started by Gregory Brown, and that nowadays counts with some other awesome [...]]]></description>
			<content:encoded><![CDATA[<p>Today I want to show you a project I&#8217;ve started over a year ago, during <a href="http://mendicantuniversity.org/" title="Mendicant University" target="_blank">Mendicant University</a> core skills course. For those who don&#8217;t know, Mendicant University is a group of skilled software developers that offer courses, mentoring, and help out the community, started by <a href="http://majesticseacreature.com/" target="_blank" title="Gregory Brown">Gregory Brown</a>, and that nowadays counts with some other awesome folks as part of the staff. I highly recommend taking a look at and enrolling.</p>
<p>Back to I18n, during Mendicant University we were supposed to create a project in Ruby, not specifically with Rails, and I decided to scratch my own itch by trying to solve a problem we usually have in Brazil: receiving date/time/numeric input from user interface. I know and have already used the <a href="https://github.com/clemens/delocalize" title="delocalized">delocalized gem</a>, and it works quite nice, but sometimes I felt a bit uncomfortable about how it handled some parts of localization/parsing. This is mainly due to the need to monkey patch both ActiveRecord to handle input, and ActionView to handle output. Besides that, and most important, I had to come up with some project and I thought that&#8217;d be a good challenge <img src='http://blog.plataformatec.com.br/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
<p>The main goal of this project is to provide a proxy object to use with your ORM (currently ActiveRecord only) that will be responsible for localizing and parsing the date/time/numeric attributes when getting or setting their values, respectively. Lets see some quick examples:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Include the proxy in your model</span>
<span style="color:#9966CC; font-weight:bold;">class</span> Product <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">I18n::Alchemy</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Grab your object from the database</span>
<span style="color:#0066ff; font-weight:bold;">@product</span>   = Product.<span style="color:#9900CC;">first</span>
<span style="color:#008000; font-style:italic;"># Instantiate the localized proxy</span>
<span style="color:#0066ff; font-weight:bold;">@localized</span> = <span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">localized</span></pre></div></div>

<p>Now that we have a localized proxy for the <code>@product</code> object, we can get/set numeric attributes with localized values, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">price</span> = <span style="color:#996600;">&quot;1.99&quot;</span>
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">price</span>   <span style="color:#008000; font-style:italic;"># =&gt; 1.99</span>
<span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">price</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;1.99&quot;</span>
&nbsp;
I18n.<span style="color:#9900CC;">with_locale</span> <span style="color:#ff3333; font-weight:bold;">:pt</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">price</span> = <span style="color:#996600;">&quot;1,88&quot;</span>
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">price</span>   <span style="color:#008000; font-style:italic;"># =&gt; 1.88</span>
  <span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">price</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;1,88&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And also date/time attributes, for instance:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">released_at</span> = <span style="color:#996600;">&quot;12/31/2011&quot;</span>
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">released_at</span>   <span style="color:#008000; font-style:italic;"># =&gt; Date.new(2011, 12, 31)</span>
<span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">released_at</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;12/31/2011&quot;</span>
&nbsp;
I18n.<span style="color:#9900CC;">with_locale</span> <span style="color:#ff3333; font-weight:bold;">:pt</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">released_at</span> = <span style="color:#996600;">&quot;31/12/2011&quot;</span>
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">released_at</span>   <span style="color:#008000; font-style:italic;"># =&gt; Date.new(2011, 12, 31)</span>
  <span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">released_at</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;31/12/2011&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I18n Alchemy can also receive a hash of attributes, the same way you use with your models when calling <code>new</code>. That means you can use it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># You could be using params[:product] for instance.</span>
I18n.<span style="color:#9900CC;">with_locale</span> <span style="color:#ff3333; font-weight:bold;">:pt</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@localized</span> = <span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">localized</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:price</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;1,88&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@product</span>.<span style="color:#9900CC;">price</span>   <span style="color:#008000; font-style:italic;"># =&gt; 1.88</span>
  <span style="color:#0066ff; font-weight:bold;">@localized</span>.<span style="color:#9900CC;">price</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;1,88&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The parsing/localization formats are basically the same ones you already use in your Rails application. You can check the basic locale configuration for <a href="https://github.com/carlosantoniodasilva/i18n_alchemy" title="I18n Alchemy - date/number parsing/localization">I18n Alchemy in its README on github</a>.</p>
<h2>Wrapping up</h2>
<p>I18n Alchemy is a small and new project which solves most of the problems we commonly face when dealing with localization and parsing of date/time/numeric values. It is tested with Rails 3.0, 3.1 and 3.2 and works with all the basic methods, such as <code>attributes=</code>, <code>assign_attributes</code>, <code>update_attributes</code> and nested attributes as well.</p>
<p>It was a really fun time creating it during Mendicant University, and it took a long time until I decided to release it as a gem. There is still a bunch of things to do, but I wanted to ask you to give it a try and let me know about any feedback you have.</p>
<p>As a side note, if you are interested in knowing more about the design decisions that led this project, you may want to take a look at <a href="http://blog.rubybestpractices.com/posts/gregory/055-issue-23-solid-design.html" title="Ruby Best Practices: Issue #23: SOLID Design Principles">Gregory Brown&#8217;s post on Ruby Best Practices, entitled &#8220;Issue #23: SOLID Design Principles&#8221;</a>, more specifically in the Open/closed principle topic.</p>
<p>I&#8217;m releasing the first 0.0.1 version today, and I hope you find it useful. Have any comments? Let us know!</p>
<img src="http://feeds.feedburner.com/~r/PlataformaBlog/~4/wJUlCUKSCWM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.plataformatec.com.br/2012/05/i18n-alchemy-localization-and-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.plataformatec.com.br/2012/05/i18n-alchemy-localization-and-parsing/</feedburner:origLink></item>
		<item>
		<title>Our new visual identity and website! =D</title>
		<link>http://feedproxy.google.com/~r/PlataformaBlog/~3/dqJau0PW1wc/</link>
		<comments>http://blog.plataformatec.com.br/2012/03/our-new-visual-identity-and-website-d/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 20:48:38 +0000</pubDate>
		<dc:creator>Marcelo Park</dc:creator>
				<category><![CDATA[English]]></category>

		<guid isPermaLink="false">http://blog.plataformatec.com.br/?p=2595</guid>
		<description><![CDATA[We are excited to present our new visual identity and website.]]></description>
			<content:encoded><![CDATA[<p>Hello friends!</p>
<p>We are excited to present our new visual identity and website.</p>
<p>We felt that it was time to give a step further into the way people see us. Our previous visual identity was very dense and the logo had a very strong appeal to &#8220;engineering&#8221;. It felt very solid and we liked it. But since we&#8217;ve founded Plataformatec we have learnt lots of new things, launched dozens of apps and we&#8217;ve met new great clients. Because of this, we brought new people onboard to complement us, with skills we didn&#8217;t have before.</p>
<p>Today, our team has engineers, designers, agile project managers and some business guys too. It would be more accurate if our visual identity incorporated them too. We still like to be seen as software engineers, but now, our team and services scope has grown.</p>
<p>We hope you like our new look.</p>
<p>Don&#8217;t be shy! Take a look into our <strong><a title="Plataformatec" href="http://plataformatec.com.br">new website</a></strong> and our <strong><a title="Plataformatec's Facebook page" href="http://facebook.com/plataformatec.com.br">page on Facebook</a></strong> and tell us what you think.</p>
<p>By the way, we&#8217;ll keep using @plataformatec twitter account for announcements, so keep following us. <img src='http://blog.plataformatec.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/PlataformaBlog/~4/dqJau0PW1wc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.plataformatec.com.br/2012/03/our-new-visual-identity-and-website-d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.plataformatec.com.br/2012/03/our-new-visual-identity-and-website-d/</feedburner:origLink></item>
		<item>
		<title>Barebone models to use with ActionPack in Rails 4.0</title>
		<link>http://feedproxy.google.com/~r/PlataformaBlog/~3/Mm-rrHIMb1s/</link>
		<comments>http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 18:40:36 +0000</pubDate>
		<dc:creator>Carlos Antônio</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[activemodel]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 4]]></category>

		<guid isPermaLink="false">http://blog.plataformatec.com.br/?p=2543</guid>
		<description><![CDATA[Rails 4 will ship with ActiveModel::Model, a module that includes the minimum required by Action Pack to work in forms, urls and so forth. Learn more about this module, how to use and extend it in this blog post.]]></description>
			<content:encoded><![CDATA[<p>Rails 4.0 &#8211; current master branch at the time of this writing &#8211; <a href="https://github.com/rails/rails/commit/3b822e91d1a6c4eab0064989bbd07aae3a6d0d08" title="Rails 4.0: ActiveModel::Model">has recently got a small &#8211; yet very useful &#8211; addition: <code>ActiveModel::Model</code></a>. The implementation is really simple, as you can see below:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveModel
  <span style="color:#9966CC; font-weight:bold;">module</span> Model
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
      base.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        extend  <span style="color:#6666ff; font-weight:bold;">ActiveModel::Naming</span>
        extend  <span style="color:#6666ff; font-weight:bold;">ActiveModel::Translation</span>
        <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Validations</span>
        <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Conversion</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> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>params=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      params.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attr, value<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">public_send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{attr}=&quot;</span>, value<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;">if</span> params
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> persisted?
      <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>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Quite straightforward, huh? But what does it do, and what are we supposed to do with it?</p>
<h3>ActiveModel::Model: Basic Model implementation</h3>
<p><a href="https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb#L3" title="ActiveModel::Model docs">According to the docs</a>, <em><code>ActiveModel::Model</code> includes all the required interface for an object to interact with <code>ActionPack</code>, using different <code>ActiveModel</code> modules. It includes model name instrospection, conversions, translations and validations. In addition to that, it allows you to initialize the object with a hash of attributes, pretty much like <code>ActiveRecord</code> does.</em></p>
<p>Wait, what? In short: you can easily extend <code>ActiveModel::Model</code> in a normal Ruby class and use instances of that class with helpers like <code>form_for</code>, <code>dom_id / dom_class</code>, and any other <code>ActionView</code> helper, as you do with <code>ActiveRecord</code> objects. It also gives you known method helpers such as <code>human_attribute_name</code>.</p>
<p>A minimal implementation could be:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Model</span>
&nbsp;
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:age</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:name</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
person = Person.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bob'</span>, <span style="color:#ff3333; font-weight:bold;">:age</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'18'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
person.<span style="color:#9900CC;">name</span> <span style="color:#008000; font-style:italic;"># =&gt; 'bob'</span>
person.<span style="color:#9900CC;">age</span> <span style="color:#008000; font-style:italic;"># =&gt; 18</span>
person.<span style="color:#9900CC;">valid</span>? <span style="color:#008000; font-style:italic;"># =&gt; true</span></pre></div></div>

<p>This is really handy, considering that before this addition, we&#8217;d have to add all that code to have a model up and running to use with <code>ActionView's form_for</code>, for instance. Ok, it is not that much code to add, but now we don&#8217;t even need to remember which modules are required for such integration. And I have to add that I&#8217;ve been creating similar classes in different applications lately. Take a moment to think about a contact form, that does not need to be tied to a database: it&#8217;s a common scenario to implement using <code>ActiveModel::Model</code>.</p>
<h3>Extending Basic Model even more</h3>
<p>Note that, by default, <code>ActiveModel::Model</code> implements <code>persisted?</code> to return <code>false</code>, which is the most common case. For instance, when used with <code>form_for</code>, this means that the generated url would <code>post</code> to the <code>create</code> action. You may want to override it in your class to simulate a different scenario:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Model</span>
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:id</span>, <span style="color:#ff3333; font-weight:bold;">:name</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> persisted?
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">id</span> == <span style="color:#006666;">1</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
person = Person.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bob'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
person.<span style="color:#9900CC;">persisted</span>? <span style="color:#008000; font-style:italic;"># =&gt; true</span></pre></div></div>

<p>Besides that, if for some reason you need to run code on <code>initialize</code>, make sure you call super if you want the attributes hash initialization to happen.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Model</span>
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:id</span>, <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:omg</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>attributes<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">super</span>
    <span style="color:#0066ff; font-weight:bold;">@omg</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
person = Person.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bob'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
person.<span style="color:#9900CC;">omg</span> <span style="color:#008000; font-style:italic;"># =&gt; true</span></pre></div></div>

<p>And remember that, at the end, this is all Ruby: you can include any other module of your own and other <code>ActiveModel</code> modules easily in your class. For instance, lets add <code>callbacks</code> to our model to mimic <code>ActiveRecord's save</code> functionality:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveModel::Model</span>
  extend <span style="color:#6666ff; font-weight:bold;">ActiveModel::Callbacks</span>
&nbsp;
  define_model_callbacks <span style="color:#ff3333; font-weight:bold;">:save</span>
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:id</span>, <span style="color:#ff3333; font-weight:bold;">:name</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Just check validity, and if so, trigger callbacks.</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> save
    <span style="color:#9966CC; font-weight:bold;">if</span> valid?
      run_callbacks<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:save</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</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;">else</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>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This gives you <code>before_save</code>, <code>after_save</code> and <code>around_save</code> callbacks. Quick and easy, huh?</p>
<h3>Wrapping up</h3>
<p><code>ActiveModel::Model</code> is a really small, handy addition to Rails 4.0, which helps us to get classes that act more like <code>ActiveRecord</code> and easily integrate with <code>ActionPack</code>.</p>
<p>For more detailed information on other features available, please refer to the <a href="https://github.com/rails/rails/tree/master/activemodel/lib/active_model" title="ActiveModel available modules">specific modules included in <code>ActiveModel::Model</code></a>. Each module includes plenty of docs explaining its functionality. Apart from these included modules, <code>ActiveModel</code> itself has a bunch of useful stuff to add to your Ruby classes that are really worth checking out.</p>
<p>This is the kind of thing that makes me a happier Rails developer every day. What about you, what makes you a happier Rails developer? Please take a moment to tell us in the comments section below <img src='http://blog.plataformatec.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/PlataformaBlog/~4/Mm-rrHIMb1s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/</feedburner:origLink></item>
		<item>
		<title>SimpleForm 2.0 + Bootstrap: for you with love</title>
		<link>http://feedproxy.google.com/~r/PlataformaBlog/~3/zqa2064mUZc/</link>
		<comments>http://blog.plataformatec.com.br/2012/02/simpleform-2-0-bootstrap-for-you-with-love/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 16:54:25 +0000</pubDate>
		<dc:creator>Rafael França</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[simple_form]]></category>
		<category><![CDATA[twitter bootstrap]]></category>

		<guid isPermaLink="false">http://blog.plataformatec.com.br/?p=2469</guid>
		<description><![CDATA[The Carnival is over in Brazil but we are still partying at Plataformatec by bringing you, not a small bump, but a shiny new version: Simple Form 2.0. Simple Form 2.0 features a new wrapper API which makes it very flexible and easy to integrate with CSS frameworks like Twitter Bootstrap. ]]></description>
			<content:encoded><![CDATA[<p>The Carnival is over in Brazil but we are still partying at Plataformatec by bringing you a complete new release of SimpleForm. This time is not a small bump though, it&#8217;s a shiny new version: <a href="https://github.com/plataformatec/simple_form" title="SimpleForm">SimpleForm 2.0</a>, that comes with a bunch of new features and customizations, a new wrapper API to create custom input stacks and a great integration with <a href="http://twitter.github.com/bootstrap" title="Twitter Bootstrap">Twitter Bootstrap</a>.</p>
<h3>Wrappers API</h3>
<p>The new wrappers API is here in place of the old <code>components</code> option (besides some other *_tag and *_class configs), to add more flexibility to the way you build SimpleForm inputs. Here is an example of the default wrapper config that ships with SimpleForm when you run its install generator:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">wrappers</span> <span style="color:#ff3333; font-weight:bold;">:default</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:input</span>,
  <span style="color:#ff3333; font-weight:bold;">:hint_class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:field_with_hint</span>, <span style="color:#ff3333; font-weight:bold;">:error_class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:field_with_errors</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#008000; font-style:italic;">## Extensions enabled by default</span>
  <span style="color:#008000; font-style:italic;"># Any of these extensions can be disabled for a</span>
  <span style="color:#008000; font-style:italic;"># given input by passing: `f.input EXTENSION_NAME =&gt; false`.</span>
  <span style="color:#008000; font-style:italic;"># You can make any of these extensions optional by</span>
  <span style="color:#008000; font-style:italic;"># renaming `b.use` to `b.optional`.</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Determines whether to use HTML5 (:email, :url, ...)</span>
  <span style="color:#008000; font-style:italic;"># and required attributes</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:html5</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Calculates placeholders automatically from I18n</span>
  <span style="color:#008000; font-style:italic;"># You can also pass a string as f.input :placeholder =&gt; &quot;Placeholder&quot;</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:placeholder</span>
&nbsp;
  <span style="color:#008000; font-style:italic;">## Optional extensions</span>
  <span style="color:#008000; font-style:italic;"># They are disabled unless you pass `f.input EXTENSION_NAME =&gt; :lookup`</span>
  <span style="color:#008000; font-style:italic;"># to the input. If so, they will retrieve the values from the model</span>
  <span style="color:#008000; font-style:italic;"># if any exists. If you want to enable the lookup for any of those</span>
  <span style="color:#008000; font-style:italic;"># extensions by default, you can change `b.optional` to `b.use`.</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Calculates maxlength from length validations for string inputs</span>
  b.<span style="color:#9900CC;">optional</span> <span style="color:#ff3333; font-weight:bold;">:maxlength</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Calculates pattern from format validations for string inputs</span>
  b.<span style="color:#9900CC;">optional</span> <span style="color:#ff3333; font-weight:bold;">:pattern</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Calculates min and max from length validations for numeric inputs</span>
  b.<span style="color:#9900CC;">optional</span> <span style="color:#ff3333; font-weight:bold;">:min_max</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Calculates readonly automatically from readonly attributes</span>
  b.<span style="color:#9900CC;">optional</span> <span style="color:#ff3333; font-weight:bold;">:readonly</span>
&nbsp;
  <span style="color:#008000; font-style:italic;">## Inputs</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:label_input</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:hint</span>,  <span style="color:#ff3333; font-weight:bold;">:wrap_with</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;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:span</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:hint</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:error</span>, <span style="color:#ff3333; font-weight:bold;">:wrap_with</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;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:span</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:error</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Wrappers are used by the form builder to generate a complete input. You can remove any component from the wrapper, change the order or even add your own to the stack.</p>
<p>The <code>:default</code> wrapper is going to be used in all forms by default. You can also select which wrapper to use per form, by naming them:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Given you added this wrapper in your SimpleForm initializer:</span>
config.<span style="color:#9900CC;">wrappers</span> <span style="color:#ff3333; font-weight:bold;">:small</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:placeholder</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:label_input</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Uses the :small wrapper for all inputs in this form.</span>
simple_form_for <span style="color:#0066ff; font-weight:bold;">@user</span>, <span style="color:#ff3333; font-weight:bold;">:wrapper</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:small</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
  f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:name</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Or you can just pick a different wrapper in a specific input if you want:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Uses the default wrapper for other inputs, and :small for :name.</span>
simple_form_for <span style="color:#0066ff; font-weight:bold;">@user</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
  f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:wrapper</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:small</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>You can see a more detailed description of the new <a href="http://simple-form.plataformatec.com.br/#configuration/the-wrappers-api" title="SimpleForm 2.0 wrappers API docs">wrappers API in the documentation</a>.</p>
<h3>Twitter Bootstrap</h3>
<p>The second big change in SimpleForm 2.0 is out of the box Bootstrap integration. SimpleForm now ships with a generator option to initialize your application with a set of specific wrappers customized for Bootstrap. To get them, just run in your terminal, inside a Rails application (with SimpleForm already installed):</p>
<pre>
rails generate simple_form:install --bootstrap
</pre>
<p>This gives you the default SimpleForm initializer in <code>config/initializers/simple_form.rb</code> with some extra integration code added for Bootstrap. For example, here is the default wrapper:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">wrappers</span> <span style="color:#ff3333; font-weight:bold;">:bootstrap</span>, <span style="color:#ff3333; font-weight:bold;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'div'</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'control-group'</span>, 
  <span style="color:#ff3333; font-weight:bold;">:error_class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'error'</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>b<span style="color:#006600; font-weight:bold;">|</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:placeholder</span>
  b.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:label</span>
  b.<span style="color:#9900CC;">wrapper</span> <span style="color:#ff3333; font-weight:bold;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'div'</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'controls'</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>ba<span style="color:#006600; font-weight:bold;">|</span>
    ba.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:input</span>
    ba.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:error</span>, <span style="color:#ff3333; font-weight:bold;">:wrap_with</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;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'span'</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'help-inline'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    ba.<span style="color:#9900CC;">use</span> <span style="color:#ff3333; font-weight:bold;">:hint</span>,  <span style="color:#ff3333; font-weight:bold;">:wrap_with</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;">:tag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'p'</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'help-block'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This wrapper is setup with the same structure that Bootstrap expects and is set to be the default wrapper in your application. This is <strong>the killer feature in SimpleForm 2.0</strong>: the Bootstrap integration is not inside SimpleForm but all in your application. This means that, if you want to move away or customize Bootstrap in the future, you don&#8217;t need to monkey patch SimpleForm, everything is in your app!</p>
<p>We&#8217;ve set up a <a href="http://simple-form-bootstrap.plataformatec.com.br/articles/new" title="SimpleForm Bootstrap example application">live example application showing most of the SimpleForm inputs integrated with Twitter Bootstrap</a>, make sure you check it out! The <a href="https://github.com/rafaelfranca/simple_form-bootstrap" title="SimpleForm Bootstrap example application code">application code is on github</a>.</p>
<p>Keep reading this blog post to find out the other changes and deprecations that gave SimpleForm all this extra flexibility, allowing it to be easily integrated with Twitter Bootstrap 2.0. </p>
<h3>New configs</h3>
<p>SimpleForm 2.0 comes with some new configs to ease its integration with Bootstrap and to make your daily work even more flexible:</p>
<ul>
<li><code>default_wrapper</code>: defines the default wrapper to be used when no one is given.</li>
<li><code>button_class</code>: defines a class to add for all buttons.</li>
<li><code>boolean_style</code>: change the way booleans (mainly check boxes and radio buttons) are shown: <code>:inline</code> (the default) uses the same structure as before, checkbox + label; <code>:nested</code> (generated for new apps) puts the checkbox inside the label, as label > checkbox.</li>
<li><code>collection_wrapper_class</code>: class to add in all collections (check boxes / radio buttons), given <code>collection_wrapper_tag</code> is set.</li>
<li><code>item_wrapper_class</code>: class to add to all items in a collection.</li>
<li><code>generate_additional_classes_for</code>: allows you to specify whether to generate the extra css classes for inputs, labels and wrappers. By default SimpleForm always generate all classes, such as input type and required info, to all of them. You can be more selective and tell SimpleForm to just add such classes to the input or wrapper, by changing this config.</li>
</ul>
<h3>Deprecations</h3>
<p>In order to create the new wrappers API, we had to deprecate some configs and change some helpers, so here is a basic summary of what is being deprecated:</p>
<h4>Configs</h4>
<ul>
<li><code>translate</code>: By making <code>placeholder</code> and <code>hint</code> <code>optional</code> options in the wrappers API, you can already disable the automatic translation attempt that happens for these components. <code>labels</code>, on the other hand, are always used in forms, so we added a special config for them: <code>translate_labels</code>.</li>
<li><code>html5</code>: this config is now part of the wrappers API, with <code>b.use :html5</code>, so the config option has been deprecated.</li>
<li><code>error_notification_id</code>: in favor of using <code>error_notification_class</code> only.</li>
<li><code>wrapper_tag=, wrapper_class=, wrapper_error_class=, error_tag=, error_class=, hint_tag=, hint_class=, components=</code>: all these were moved to the wrappers API structure, and are not required anymore.</li>
</ul>
<h4>Helpers</h4>
<ul>
<li><code>:radio</code> input type: In order to integrate with Bootstrap, we had to get rid of the <code>:as => :radio</code> and use <code>:as => :radio_buttons</code> instead. The former still works, but will give you a bunch of deprecation warnings. CSS class names changed accordingly as well</li>
<li><code>collection_radio</code>: has changed to <code>collection_radio_buttons</code> to follow the <code>:as => :radio_buttons</code> change. Its label class has changed as well based on the helper name.</li>
</ul>
<h3>Wrapping up</h3>
<p>SimpleForm 2.0 comes with a lot of new features, in special the new wrappers API, to make it flexible enough to allow you to customize inputs as much as possible in an easier way, and to bring you the integrated Bootstrap structure.</p>
<p>Make sure you check out the new <a href="http://simple-form.plataformatec.com.br" title="SimpleForm README">SimpleForm README</a> and also the <a href="https://github.com/plataformatec/simple_form/blob/master/CHANGELOG.md" title="SimpleForm CHANGELOG">CHANGELOG</a> for a full list of changes. We&#8217;ve also created an special wiki page to help you <a href="https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0" title="Upgrading to SimpleForm 2.0">Upgrading to SimpleForm 2.0</a>. </p>
<p>If you find any trouble while migrating to 2.0, or any issue with Bootstrap integration, or any other issue, please let us know in the <a href="https://github.com/plataformatec/simple_form/issues" title="SimpleForm issues tracker">issues tracker</a>. And if you have any questions, make sure to send them to the <a href="http://groups.google.com/group/plataformatec-simpleform" title="SimpleForm mailing list">mailing list</a>, there are a lot of people there to help you.</p>
<p>All our development team and an <a href="https://github.com/plataformatec/simple_form/contributors" title="SimpleForm contributors">amazing number of contributors</a> put a lot of effort into this new release and we hope you will enjoy it. SimpleForm 2.0 + Bootstrap: from us, for you, with love.</p>
<p>Thoughts about SimpleForm 2.0? Please let us know in the comments.</p>
<img src="http://feeds.feedburner.com/~r/PlataformaBlog/~4/zqa2064mUZc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.plataformatec.com.br/2012/02/simpleform-2-0-bootstrap-for-you-with-love/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.plataformatec.com.br/2012/02/simpleform-2-0-bootstrap-for-you-with-love/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: blog.plataformatec.com.br @ 2012-05-17 19:06:06 -->

