From 366656c9aa8310141735d51e2110c7db1b97080a Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 18 Jun 2010 16:16:58 -0300 Subject: [PATCH] Update README block helpers to the new erb blocks in Rails 3 --- README.rdoc | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.rdoc b/README.rdoc index d1692121..0569fa17 100644 --- a/README.rdoc +++ b/README.rdoc @@ -29,61 +29,61 @@ SimpleForm was designed to be customized as you need to. Basically it's a stack To start using SimpleForm you just have to use the helper it provides: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :username %> <%= f.input :password %> <%= f.button :submit %> - <% end -%> + <% end %> This will generate an entire form with labels for user name and password as well, and render errors by default when you render the form with invalid data (after submitting for example). You can overwrite the default label by passing it to the input method, or even add a hint: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :username, :label => 'Your username please' %> <%= f.input :password, :hint => 'No special characters.' %> <%= f.button :submit %> - <% end -%> + <% end %> You can also disable labels, hints or error or configure the html of any of them: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :username, :label_html => { :class => 'my_class' } %> <%= f.input :password, :hint => false, :error_html => { :id => "password_error"} %> <%= f.input :password_confirmation, :label => false %> <%= f.button :submit %> - <% end -%> + <% end %> By default all inputs are required, which means an * is prepended to the label, but you can disable it in any input you want: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :name, :required => false %> <%= f.input :username %> <%= f.input :password %> <%= f.button :submit %> - <% end -%> + <% end %> SimpleForm also lets you overwrite the default input type it creates: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :username %> <%= f.input :password %> <%= f.input :description, :as => :text %> <%= f.input :accepts, :as => :radio %> <%= f.button :submit %> - <% end -%> + <% end %> So instead of a checkbox for the :accepts attribute, you'll have a pair of radio buttons with yes/no labels and a text area instead of a text field for the description. You can also render boolean attributes using :as => :select to show a dropdown. SimpleForm also allows you using label, hint and error helpers it provides: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.label :username %> <%= f.text_field :username %> <%= f.error :username, :id => 'user_name_error' %> <%= f.hint 'No special characters, please!' %> <%= f.submit 'Save' %> - <% end -%> + <% end %> Any extra option passed to label, hint or error will be rendered as html option. @@ -91,11 +91,11 @@ Any extra option passed to label, hint or error will be rendered as html option. And what if you want to create a select containing the age from 18 to 60 in your form? You can do it overriding the :collection option: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :user %> <%= f.input :age, :collection => 18..60 %> <%= f.button :submit %> - <% end -%> + <% end %> Collections can be arrays or ranges, and when a :collection is given the :select input will be rendered by default, so we don't need to pass the :as => :select option. Other types of collection are :radio and :check_boxes. Those are added by SimpleForm to Rails set of form helpers (read Extra Helpers session below for more information). @@ -127,11 +127,11 @@ The first step is to configure a wrapper tag: And now, you don't need to wrap your f.input calls anymore: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :username %> <%= f.input :password %> <%= f.button :submit %> - <% end -%> + <% end %> == Associations @@ -152,12 +152,12 @@ To deal with associations, SimpleForm can generate select inputs, a series of ra Now we have the user form: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :name %> <%= f.association :company %> <%= f.association :roles %> <%= f.button :submit %> - <% end -%> + <% end %> Simple enough right? This is going to render a :select input for choosing the :company, and another :select input with :multiple option for the :roles. You can of course change it, to use radios and check boxes as well: @@ -172,10 +172,10 @@ The association helper just invokes input under the hood, so all options availab All web forms need buttons, right? SimpleForm wraps them in the DSL, acting like a proxy: - <% simple_form_for @user do |f| -%> + <%= simple_form_for @user do |f| %> <%= f.input :name %> <%= f.button :submit %> - <% end -%> + <% end %> The above will simply call submit. You choose to use it or not, it's just a question of taste.