<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>activemodel « Plataformatec Blog</title>
	<atom:link href="/tag/activemodel/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>Plataformatec&#039;s place to talk about Ruby, Ruby on Rails, Elixir, and software engineering</description>
	<lastBuildDate>Tue, 04 Sep 2012 16:27:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.2</generator>
	<item>
		<title>Talks da RubyConf Brasil 2012</title>
		<link>/2012/09/talks-da-rubyconf-brasil-2012/</link>
		
		<dc:creator><![CDATA[Carlos Antônio]]></dc:creator>
		<pubDate>Tue, 04 Sep 2012 16:27:25 +0000</pubDate>
				<category><![CDATA[Português]]></category>
		<category><![CDATA[activemodel]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[copyright]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 4]]></category>
		<category><![CDATA[rubyconfbr]]></category>
		<category><![CDATA[talks]]></category>
		<guid isPermaLink="false">/?p=3091</guid>

					<description><![CDATA[<p>A Plataformatec esteve presente na RubyConf Brasil 2012 com palestras e lightning talks. O evento teve mais de 750 participantes e mais de 500 pessoas assistindo online. As palestras foram: Vamos falar sobre Concorrência, por José Valim; Escrevendo Aplicações Melhores com Active Model, por Carlos Antonio; e Conhecendo as Entranhas do Rails, por Rafael França. E os lightning talks foram: Contribuindo para o Rails, por Carlos Galdino; I18nAlchemy, por Lucas Mazza; e Copyright, Licenças Open Source e você!, por George Guimarães.</p>
<p>The post <a href="/2012/09/talks-da-rubyconf-brasil-2012/">Talks da RubyConf Brasil 2012</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Nos dias 30 e 31 de Agosto de 2012, aconteceu o maior evento de Ruby da América Latina: a <a href="http://rubyconf.com.br/" title="RubyConf Brasil">RubyConf Brasil</a>, e a Plataformatec marcou presença com palestras e lightning talks. O evento foi um sucesso, com mais de 750 participantes durante a conferência, e mais de 500 pessoas assistindo o evento online através do site da <a href="http://www.eventials.com/rubyconfbr2012" title="RubyConfBR 2012 - Vídeos">Eventials</a>.</p>
<p><a href="/2012/09/talks-da-rubyconf-brasil-2012/ptec_team/" rel="attachment wp-att-3100"><img fetchpriority="high" decoding="async" src="/wp-content/uploads/2012/09/ptec_team.jpg" alt="Plataformatec Team" title="Plataformatec Team" width="600" height="398" class="aligncenter size-full wp-image-3100" srcset="/wp-content/uploads/2012/09/ptec_team.jpg 600w, /wp-content/uploads/2012/09/ptec_team-300x199.jpg 300w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p>Abaixo você pode ver os temas, com links para os slides e vídeos:</p>
<h3>Palestras</h3>
<h4>Vamos falar sobre Concorrência</h4>
<p><script async class="speakerdeck-embed" data-id="5046019de76a640002006e42" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script></p>
<p>Por José Valim. <a href="http://www.eventials.com/rubyconfbr2012/recorded/M2UzZTJkMzY2MzdiNTg2NTUxNWM1MzI3NWY1YjRhMzYjIzEyOTk_3D" title="Vamos falar sobre Concorrência - José Valim - RubyConf Brasil 2012">Confira o vídeo</a>.</p>
<h4>Escrevendo Aplicações Melhores com Active Model</h4>
<p><script async class="speakerdeck-embed" data-id="5046049ee76a6400020080b4" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script></p>
<p>Por Carlos Antonio. <a href="http://www.eventials.com/rubyconfbr2012/recorded/M2UzZTJkMzY2MzdiNTg2NTUxNWM1MzI3NWY1YjRhMzYjIzEzMDI_3D" title="Escrevendo Aplicações Melhores com Active Model - Carlos Antonio - RubyConf Brasil 2012">Confira o vídeo</a>.</p>
<h4>Conhecendo as Entranhas do Rails</h4>
<p><script async class="speakerdeck-embed" data-id="504605d9e76a640002008854" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script></p>
<p>Por Rafael França. <a href="http://www.eventials.com/rubyconfbr2012/recorded/M2UzZTJkMzY2MzdiNTg2NTUxNWM1MzI3NWY1YjRhMzYjIzEzMDM_3D" title="Conhecendo as Entranhas do Rails - Rafael França - RubyConf Brasil 2012">Confira o vídeo</a>.</p>
<h3>Lightning Talks</h3>
<h4>Contribuindo para o Rails</h4>
<p><script async class="speakerdeck-embed" data-id="50460791dd297e0002009176" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script></p>
<p>Por Carlos Galdino.</p>
<h4>I18nAlchemy</h4>
<p><script async class="speakerdeck-embed" data-id="504607d0e76a640002009384" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script></p>
<p>Por Lucas Mazza.</p>
<h4>Copyright, Licenças Open Source e você!</h4>
<p><script async class="speakerdeck-embed" data-id="5046081cdd297e00020094f3" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script></p>
<p>Por George Guimarães.</p>
<p><a href="http://www.eventials.com/rubyconfbr2012/recorded/M2UzZTJkMzY2MzdiNTg2NTUxNWM1MzI3NWY1YjRhMzYjIzEyOTg_3D" title="Lightning Talks - RubyConf Brasil 2012">Confira o vídeo das Lightning Talks</a>.</p>
<p>Sinta-se à vontade para ver e rever os slides e vídeos das palestras, e nos passar seu feedback através dos comentários. Não deixe também de conferir as outras palestras disponíveis, e se você escreveu um post sobre o evento em seu blog, adoraríamos ver um comentário com um link compartilhando seu post.</p>
<p>Gostaríamos também de agradecer e parabenizar o Fábio Akita e a Locaweb pela ótima organização e alta qualidade do evento, tudo funcionou perfeitamente para que todos pudessem aproveitar ao máximo a conferência.</p>
<p>E nos vemos na RubyConf Brasil 2013!</p><p>The post <a href="/2012/09/talks-da-rubyconf-brasil-2012/">Talks da RubyConf Brasil 2012</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Plataformatec na RubyConf 2012</title>
		<link>/2012/08/plataformatec-na-ruby-conf-2012/</link>
		
		<dc:creator><![CDATA[Rodrigo Flores]]></dc:creator>
		<pubDate>Wed, 29 Aug 2012 18:17:47 +0000</pubDate>
				<category><![CDATA[Português]]></category>
		<category><![CDATA[activemodel]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[copyright]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails 4]]></category>
		<category><![CDATA[rubyconfbr]]></category>
		<category><![CDATA[talks]]></category>
		<guid isPermaLink="false">/?p=3059</guid>

					<description><![CDATA[<p>Nos próximos dias 30 e 31 de agosto, estaremos presentes na Ruby Conf Brasil com três palestrantes! No dia 31, às 9h40, José Valim falará na Sala 1 sobre concorrência e sobre o papel e a importância disso no desenvolvimento de aplicações. Às 11h, na sala 2, Carlos Antonio falará sobre como usar Active Model ... <a class="read-more-link" href="/2012/08/plataformatec-na-ruby-conf-2012/">»</a></p>
<p>The post <a href="/2012/08/plataformatec-na-ruby-conf-2012/">Plataformatec na RubyConf 2012</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Nos próximos dias 30 e 31 de agosto, estaremos presentes na <a href="http://www.rubyconf.com.br/">Ruby Conf Brasil</a> com três palestrantes!</p>
<p>No dia 31, às 9h40, <a href="http://www.rubyconf.com.br/pt-BR/speakers/jose-valim">José Valim</a> falará na Sala 1 sobre concorrência e sobre o papel e a importância disso no desenvolvimento de aplicações.</p>
<p>Às 11h, na sala 2, <a href="http://www.rubyconf.com.br/pt-BR/speakers/carlos-antonio-da-silva">Carlos Antonio</a> falará sobre como usar Active Model para escrevermos aplicações melhores.</p>
<p>Por fim, às 11h50, na sala 1, <a href="http://www.rubyconf.com.br/pt-BR/speakers/rafael-franca">Rafael França</a> falará sobre as entranhas do Rails e as grandes novidades do Rails 4.</p>
<p>Não deixe também de votar em nossos Lightning Talks, que serão realizados no primeiro dia, a partir das 18h20:</p>
<ul>
<li><a href="http://call4paperz.com/events/lightning-talk-rubyconf-brasil-2012/proposals/517">Contribuindo para o Rails</a>, do Carlos Galdino</li>
<li><a href="http://call4paperz.com/events/lightning-talk-rubyconf-brasil-2012/proposals/518">I18nAlchemy</a>, do Lucas Mazza </li>
<li><a href="http://call4paperz.com/events/lightning-talk-rubyconf-brasil-2012/proposals/516">Copyright, Licenças Open Source e você!</a>, do George Guimarães</li>
</ul>
<p>Nos vemos lá!</p><p>The post <a href="/2012/08/plataformatec-na-ruby-conf-2012/">Plataformatec na RubyConf 2012</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Barebone models to use with ActionPack in Rails 4.0</title>
		<link>/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/</link>
					<comments>/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Antônio]]></dc:creator>
		<pubDate>Tue, 06 Mar 2012 18:40:36 +0000</pubDate>
				<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">/?p=2543</guid>

					<description><![CDATA[<p>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.</p>
<p>The post <a href="/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/">Barebone models to use with ActionPack in Rails 4.0</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></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>
<pre lang="ruby">
module ActiveModel
  module Model
    def self.included(base)
      base.class_eval do
        extend  ActiveModel::Naming
        extend  ActiveModel::Translation
        include ActiveModel::Validations
        include ActiveModel::Conversion
      end
    end

    def initialize(params={})
      params.each do |attr, value|
        self.public_send("#{attr}=", value)
      end if params
    end

    def persisted?
      false
    end
  end
end
</pre>
<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>
<pre lang="ruby">
class Person
  include ActiveModel::Model

  attr_accessor :name, :age
  validates_presence_of :name
end

person = Person.new(:name => 'bob', :age => '18')
person.name # => 'bob'
person.age # => 18
person.valid? # => true
</pre>
<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>
<pre lang="ruby">
class Person
  include ActiveModel::Model
  attr_accessor :id, :name

  def persisted?
    self.id == 1
  end
end

person = Person.new(:id => 1, :name => 'bob')
person.persisted? # => true
</pre>
<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>
<pre lang="ruby">
class Person
  include ActiveModel::Model
  attr_accessor :id, :name, :omg

  def initialize(attributes)
    super
    @omg ||= true
  end
end

person = Person.new(:id => 1, :name => 'bob')
person.omg # => true
</pre>
<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>
<pre lang="ruby">
class Person
  include ActiveModel::Model
  extend ActiveModel::Callbacks

  define_model_callbacks :save
  attr_accessor :id, :name

  # Just check validity, and if so, trigger callbacks.
  def save
    if valid?
      run_callbacks(:save) { true }
    else
      false
    end
  end
end
</pre>
<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="https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p><p>The post <a href="/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/">Barebone models to use with ActionPack in Rails 4.0</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
