Jaap Haagmans The all-round IT guy

2Feb/110

Using formtastic for your authlogic forms

Formtastic drastically reduces the time it takes you to create your form views. And it can also be used for your authlogic session forms. A quick example:

/app/views/user_sessions/_form.html.erb:

1
2
3
4
5
6
7
8
<%= semantic_form_for @user_session do |f| %>
  <%= f.inputs do %>
    <%= f.input :login %>
    <%= f.input :password %>
    <%= f.input :remember_me, :as => :boolean %>
  <% end %>
  <%= f.buttons %>
<% end %>

The form above is exactly the same in a lot of my applications. If you don't need the remember_me checkbox, you can even shorten it to four lines:

/app/views/user_sessions/_form.html.erb:

1
2
3
4
<%= semantic_form_for @user_session do |f| %>
  <%= f.inputs :login, :password %>
  <%= f.buttons %>
<% end %>

Formtastic!