Skip to content
add hbs_form_for helper with automatic attribute binding to asset pipeline
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Already using haml_asset to have access to your form_for helper in the Rails 3.1 asset pipeline? Great! Maybe you're already using handlebars_assets to combine HAML and handlebars to have dynamic templates in your asset pipeline. Hopes are, by then, you got tired to add the attribute binding by hand ;)

Now either you start out and write your own Rails 3 FormBuilder, are you just drop in handlebars_haml_assets.

what it does

handlebars_haml_assets adds a new form_for command called hbs_form_for that automatically tries to figure out which attribute to bind your tags to.


= hbs_form_for :users do |u|
  = u.text_field :name

will create this for you (I've reduced the output for clarity):

  <input value="{{name}}" />

notice the Handlebars.JS binding which got automatically added for you.

Now you can start to customize things if you like - or overwrite your attribute binding, if the default does not work for you:

= hbs_form_for :users do |u|
  = u.text_field :name, value: '{{lastname}}, {{firstname}}'

Behind the scenes, all this does is to reverse_merge your options value key with the method name you're trying to access.


In order for this to work, you'll need:

  • haml_asset
  • rails >= 3.2

The hbs_form_for helper will only be available within your asset_pipeline.

Something went wrong with that request. Please try again.