Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 04, 2012
@tylerhunt Don't require the engine by default. 68892f1
@tylerhunt Use the helper to set the default form builder. eed2355
@tylerhunt Document recent changes in README.
Include details on how to use the provided Rails engine and helper.
Mention Haml requirement.
82e71e8
Showing with 33 additions and 8 deletions.
  1. +29 −4 README.md
  2. +0 −1 lib/formulate.rb
  3. +3 −3 lib/formulate/engine.rb
  4. +1 −0 lib/formulate/form_helper.rb
View
33 README.md
@@ -7,6 +7,12 @@ form builder in Rails, and a Sass stylesheet to provide some level of stylistic
normalization.
+## Haml Requirement
+
+Formulate's `FormBuilder` relies on some helper methods provided by Haml, so
+it will only work when used within Haml templates.
+
+
## Installation
Add this line to your application's `Gemfile`:
@@ -15,6 +21,13 @@ Add this line to your application's `Gemfile`:
gem 'formulate'
```
+If you want to use the Formulate's `#form_for` helper by default, an engine
+is provided that will override Rails' helper:
+
+``` ruby
+gem 'formulate', require: 'formulate/engine'
+```
+
And then execute:
$ bundle
@@ -26,12 +39,24 @@ Or install it yourself as:
## Usage
-The form builder will be used automatically whenever the `#form_for` helper is
-called, so you don't need to do anything special to start using its methods. It
-also doesn't clobber any of the built-in form builder methods, so your forms
-should continue to work without modification, giving you the ability to
+Formulate provides a helper module that can be included in your Rails
+controllers. You can also load the helper in your `ApplicationController` to
+use it across your whole app.
+
+``` ruby
+class ApplicationController < ActionController::Base
+ helper Formulate::FormHelper
+end
+```
+
+Formulate doesn't clobber any of the built-in form builder methods, so your
+forms should continue to work without modification, giving you the ability to
selectively begin using Formulate in your applications where you see fit.
+If you're using the engine, the form builder will be used automatically
+whenever the `#form_for` helper is called, so you don't need to do anything
+special to start using it.
+
## Styles
View
1 lib/formulate.rb
@@ -1,5 +1,4 @@
require 'formulate/version'
-require 'formulate/engine'
module Formulate
extend ActiveSupport::Autoload
View
6 lib/formulate/engine.rb
@@ -1,8 +1,8 @@
+require 'formulate'
+
module Formulate
class Engine < ::Rails::Engine
- initializer 'formulate.initialize', before: 'action_view.set_configs' do |app|
- app.config.action_view.default_form_builder = Formulate::FormBuilder
-
+ initializer 'formulate.initialize' do |app|
ActiveSupport.on_load(:action_view) do
include Formulate::FormHelper
end
View
1 lib/formulate/form_helper.rb
@@ -4,6 +4,7 @@ module FormHelper
def form_for(record, options={}, &proc)
options[:html] ||= {}
+ options[:builder] ||= FormBuilder
case record
when String, Symbol

No commit comments for this range

Something went wrong with that request. Please try again.