Archive for May, 2011

José Valim and Aaron Patterson at RailsConf 2011
José Valim and Aaron Patterson at RailsConf 2011 by @j3z_hh

This year me and José Valim had the pleasure of going to Baltimore, in the US, to one of the biggest Rails events of the world! RailsConf is definitely the best place to have the opportunity of meeting and talking to a lot of great Rubyists and Railers, and also attending their talks.

Not only that, we also participated (though briefly) in BohConf, the official RailsConf unconference, which was great and very well organized! The talks covered a myriad of topics, guided the exploration on some technologies and counted with the presence of the Ruby Mendicant University students. José Valim presented a tutorial on his own Elixir, showing how to build a chat server using some cool stuff that both Elixir and Erlang provide. The code used on the tutorial is available on Valim’s GitHub.

Also, José Valim presented a talk on the ongoing Rails refactoring, guiding through the SOLID Principles and the changes in rails’ own code. You can get the slides at his RailsConf page. While you’re at it, please rate and give your feedback if you watched it live!

In this edition of RailsConf, DHH presented the “assets revolution” part of Rails 3.1 and why CoffeeScript was adopted. It doesn’t matter if you’re into CoffeeScript or not, Rails now has amazing internals to deal with assets, raising them as “first-class citizens”. You can have this on the latest Release Candidate that was released last week. The keynote is available on Youtube.

Regarding Keynotes, RailsConf 2011 had amazing ones. I strongly recommend you to watch Eric Reies’ Lessons Learned, regarding delivering products and learning from your mistakes, from his upcoming book with the same title.

Tenderlove (or sometimes known as Aaron Patterson) presented a very good talk about database query caching and proposed a future Rails refactoring to restructure the rack middleware stack in order to make it better and faster. A must watch talk! Check it on Youtube: Aaron Patterson’s Double Dream Hands: So Intense! (fast forward to minute 40 or so for a surprise)!

The talks themselves were good, in general. Highlights, in my opinion, are:

  • Aman Gupta’s Rails Performance Tools was the first time I saw Aman Gupta’s presentation live. Even though he got his slides from other conferences, I have to say I was very impressed. He really knows what he is talking about and the examples were very applicable to everyday’s work. You definitely should check it out.
  • Jim Weirich and Matt Yoho’s Securing your rails application began slowly, showing easy-to-avoid security issues, but it picked up nicely, showing live examples on how to replicate the security issues described, very cool!
  • Joe Ferris’ Testing the Impossible was a very good talk. At PlataformaTec we always discuss the best ways to test code and it was very nice to see someone else’s effort on the subject, I was able to confirm some ideas and learn new ones!
  • Yehuda Katz’ Building Rails Apps For the Rick Client explained why Rails is much more than simple view helpers and then moved on to discuss API implementations. The proposed bulk api was particularly interesting and is a good example of a private protocol between the client (SproutCore) and server side (Rails) for advanced transactions and performance!

All in all, it was a great RailsConf! I had a blast, meeting people and having drinks at the parties was also one of the best parts of the conference! And what about you? What is your opinion about RailsConf, did you like it? Which were your favorite talks?

See you in 2012!

I’m pleased to say that we released SimpleForm 1.4. Like the last version, this release had a lot of contributions from the community, closing bugs and adding some nice features. Here is a brief introduction to some of the new features:

Custom Form Builders

Now you can set a custom form builder that inherits from SimpleForm::FormBuilder:

class CustomBuilder < SimpleForm::FormBuilder
  def input(attribute_name, options={}, &block)
    options[:input_html].merge! :class => 'custom'
    super
  end
end

And use it straight in the simple_form_for helper, like the example below:

<%= simple_form_for(@user, :builder => CustomBuilder) do |f| %>
  <%= f.input :name %>
<% end %>

Custom Inputs

SimpleForm has many different inputs available in its source code. But, sometimes, depending on the business logic the application requires, we need to add new inputs to make our work easier. Before this version, you had to explicitly define your new input inside SimpleForm namespace for it to work. Furthermore, customizing existing SimpleForm inputs could only be achieved through monkey patching.

Inspired by a similar feature in the Formtastic gem, from now on you will be able to create new input types inside app/inputs folder in your application. The only restriction to create such inputs is that the class name must end with Input. See some examples:

# app/inputs/currency_input.rb
class CurrencyInput < SimpleForm::Inputs::StringInput
  def input
    "$ #{super}".html_safe
  end
end

And the usage:

f.input :money, :as => :currency

You can also redefine existing SimpleForm inputs by creating a new class with the same name. For instance, if you want to wrap date/time/datetime inputs in a div, you can do:

# app/inputs/date_time_input.rb
class DateTimeInput < SimpleForm::Inputs::DateTimeInput
  def input
    "<div>#{super}</div>".html_safe
  end
end

HTML 5

SimpleForm allows you to add many HTML 5 features to your applications, like placeholders, inline browser validations and more. The problem is: most browsers are still experimenting some HTML 5 features, and people started having lots of troubles with the automatic browser validation.

For this reason, SimpleForm now has an option to easily disable such form validations. You have to add this line to your SimpleForm initializer:

config.browser_validations = false

But, if HTML 5 is still not for you, you can disable all the HTML 5 stuff, by adding the configuration below to your initializer:

config.html5 = false

Notice that this option does not disable the `placeholder` component, because we believe this option is very well supported currently in mostly browsers. If you don’t want to use it as well, just remove it from the `components` option in your initializer.

More Helpers

In this version we also add two new form helpers to SimpleForm: input_field and full_error.

The full_error helper shows errors in an attribute prepending its human name. This can be used when you want to show errors on hidden fields, for instance. You can see how it works in this example:

f.full_error :token #=> <span class="error">Token is invalid</span>

The input_field helper renders only the input tag with all the facilities of SimpleForm’s input helper. It means no wrapper, error or hint will be rendered. A good example of using this helper is inside an input block:

<%= f.input :max_time, :as => :integer do %>
  <%= f.input_field :max_time, :as => :integer, :type => :range %>
  <%= content_tag :span, '1', :id => 'max_time_value' %>
<% end %>

It will render:

<div class="input integer required">
  <label class="integer required for="model_max_time">Max time <abbr title="required">*</abbr></label>
  <input class="numeric integer required" id="model_max_time" name="model[max_time]" required="required" size="50" type="range" />
  <span id="max_time_value">1</span>
</div>

Wrapping up

This version allows you to do more customizations in SimpleForm based on your applications needs. We encourage you to take a look at the CHANGELOG and also review the README to see what else is available and some more examples.

And please, check out SimpleForm contributors, we want to thank everyone who is helping us to improve SimpleForm.

Right now, we are working on Rails 3.1 compatibility for the next version. If you feel like helping us or just want to see a new feature, feel free to send us a pull request. And last, but not least, we look forward to know how SimpleForm is changing your life. Is it being helpful? How does it improve your applications? Don’t be shy, comments are welcome.