Dia 11/05/2012, realizamos um mini curso de Ruby on Rails no Secot (Semana de Computação e Tecnologia da UFSCAR de Sorocaba). Aqui vão os slides, os links mencionados no curso, o link para o código da aplicação que fizemos e também o link para o guia que usei na demonstração de Ruby.
Implementações do Ruby:
Ruby on Rails:
Comunidade:
Livros:
- The Pragmatic Programmer
- Getting Real
- Programming Ruby (Pickaxe)
- Why_’s poignant guide to Ruby
- Agile Web Development with Rails
- Crafting Rails Applications
Editores:
Sites de comunidade:
- Site oficial do Rails
- Ruby inside
- Railscasts
- Ruby weekly
- Blog Plataformatec
- Simples Idéias (Blog do Nando Vieira)
Para aprender mais sobre REST:
- Tese original do Roy Fielding sobre o REST
- How I explained Rest to my wife
- Uma rápida Introdução ao REST
Recursos para aprender mais sobre Ruby e Rails:
- Rails Guides
- Try Ruby
- Ruby on Rails tutorial book
- Rails For Zombies
- Ruby Learning
- Github Learn
- Ruby Show
- Ruby 5
- Ruby Rogues
- Api do Rails
- Rails vs Java (tem links para os outros vídeos)
Posted in English | 1 Comment »
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 – it is great to have our work recognized; thank you all for always being supportive. =D
We’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).
Without further ado we’d like to congratulate our fellow Carlos Antonio (@cantoniodasilva) and Rafael França (@rafaelfranca) for honorably earning the commit access to the Ruby on Rails repository!

@cantoniodasilva and @rafaelfranca
Guys, congratulations! \o/
We are all very happy for this great achievement. Great work!
From your friends at Plataformatec.
Tags: culture, great work, plataformatec, team
Posted in English | 2 Comments »
After 4 months of our last major version release, we’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’re eager to do the update, please check Devise’s wiki page about Upgrading from 2.0 to 2.1. You can also check the changelog or the commits between 2.0.4 and 2.1.0.
Encrytable is now a gem
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’re using the encryptable module, you should only require it on your Gemfile and you’re good to go!
Check fields
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’t know if the persistence layer provides all fields required by the behavior. For example, the database authenticatable module requires a encrypted_password 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.
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 User):
Devise::Models.check_fields!(User)
We’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 method_missing, you should be able to use this method (we’re relying that you also have implemented a working respond_to?, which is strongly recommendeded when using method_missing).
When check_fields! is called, Devise will detect the included modules in the given class and, if there is a missing attribute, it will raise a Devise::Models::MissingAttribute exception with a message telling you all required fields that doesn’t exist. You can easily use that method with your favorite test framework:
Devise::Models.check_fields!(User)
And then you will be able to check if your migrations have added the correct fields to your database.
A message to module maintainers
If you’re a maintainer of a Devise module, you should add a method to each of your modules called self.required_fields(klass) that returns an array of required fields. If the method is absent, you will get a deprecation warning.
UPDATE: Fixed a class name and corrected a grammar error.
Tags: devise, rails
Posted in English | No Comments »
Today I want to show you a project I’ve started over a year ago, during Mendicant University core skills course. For those who don’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 folks as part of the staff. I highly recommend taking a look at and enrolling.
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 delocalized gem, 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’d be a good challenge
.
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:
# Include the proxy in your model class Product < ActiveRecord::Base include I18n::Alchemy end # Grab your object from the database @product = Product.first # Instantiate the localized proxy @localized = @product.localized
Now that we have a localized proxy for the @product object, we can get/set numeric attributes with localized values, such as:
@localized.price = "1.99" @product.price # => 1.99 @localized.price # => "1.99" I18n.with_locale :pt do @localized.price = "1,88" @product.price # => 1.88 @localized.price # => "1,88" end
And also date/time attributes, for instance:
@localized.released_at = "12/31/2011" @product.released_at # => Date.new(2011, 12, 31) @localized.released_at # => "12/31/2011" I18n.with_locale :pt do @localized.released_at = "31/12/2011" @product.released_at # => Date.new(2011, 12, 31) @localized.released_at # => "31/12/2011" end
I18n Alchemy can also receive a hash of attributes, the same way you use with your models when calling new. That means you can use it like this:
# You could be using params[:product] for instance. I18n.with_locale :pt do @localized = @product.localized(:price => "1,88") @product.price # => 1.88 @localized.price # => "1,88" end
The parsing/localization formats are basically the same ones you already use in your Rails application. You can check the basic locale configuration for I18n Alchemy in its README on github.
Wrapping up
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 attributes=, assign_attributes, update_attributes and nested attributes as well.
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.
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 Gregory Brown’s post on Ruby Best Practices, entitled “Issue #23: SOLID Design Principles”, more specifically in the Open/closed principle topic.
I’m releasing the first 0.0.1 version today, and I hope you find it useful. Have any comments? Let us know!
Tags: date, i18n, localization, number, parsing, rails, ruby, time
Posted in English | Comments Off
Hello friends!
We are excited to present our new visual identity and website.
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 “engineering”. It felt very solid and we liked it. But since we’ve founded Plataformatec we have learnt lots of new things, launched dozens of apps and we’ve met new great clients. Because of this, we brought new people onboard to complement us, with skills we didn’t have before.
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.
We hope you like our new look.
Don’t be shy! Take a look into our new website and our page on Facebook and tell us what you think.
By the way, we’ll keep using @plataformatec twitter account for announcements, so keep following us.
Posted in English | Comments Off
Rails 4.0 – current master branch at the time of this writing – has recently got a small – yet very useful – addition: ActiveModel::Model. The implementation is really simple, as you can see below:
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
Quite straightforward, huh? But what does it do, and what are we supposed to do with it?
ActiveModel::Model: Basic Model implementation
According to the docs, ActiveModel::Model includes all the required interface for an object to interact with ActionPack, using different ActiveModel 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 ActiveRecord does.
Wait, what? In short: you can easily extend ActiveModel::Model in a normal Ruby class and use instances of that class with helpers like form_for, dom_id / dom_class, and any other ActionView helper, as you do with ActiveRecord objects. It also gives you known method helpers such as human_attribute_name.
A minimal implementation could be:
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
This is really handy, considering that before this addition, we’d have to add all that code to have a model up and running to use with ActionView's form_for, for instance. Ok, it is not that much code to add, but now we don’t even need to remember which modules are required for such integration. And I have to add that I’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’s a common scenario to implement using ActiveModel::Model.
Extending Basic Model even more
Note that, by default, ActiveModel::Model implements persisted? to return false, which is the most common case. For instance, when used with form_for, this means that the generated url would post to the create action. You may want to override it in your class to simulate a different scenario:
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
Besides that, if for some reason you need to run code on initialize, make sure you call super if you want the attributes hash initialization to happen.
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
And remember that, at the end, this is all Ruby: you can include any other module of your own and other ActiveModel modules easily in your class. For instance, lets add callbacks to our model to mimic ActiveRecord's save functionality:
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
This gives you before_save, after_save and around_save callbacks. Quick and easy, huh?
Wrapping up
ActiveModel::Model is a really small, handy addition to Rails 4.0, which helps us to get classes that act more like ActiveRecord and easily integrate with ActionPack.
For more detailed information on other features available, please refer to the specific modules included in ActiveModel::Model. Each module includes plenty of docs explaining its functionality. Apart from these included modules, ActiveModel itself has a bunch of useful stuff to add to your Ruby classes that are really worth checking out.
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
Tags: activemodel, open source, rails, rails 4
Posted in English | 6 Comments »

All
English only
Em português apenas