Skip to content

Commit 8e6daf2

Browse files
committed
Rename from ActiveForm to ActionForm
As suggested by @dhh > BTW, as far as "action" vs "active" goes, I'd like us to stick with this split: Action is for stuff that touches or talks to the user. Active is for internal. > So imo, it should be ActionForm vs, say, ActiveModel
1 parent 41ec958 commit 8e6daf2

39 files changed

+102
-102
lines changed

Gemfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
active_form (0.0.1)
4+
actionform (0.0.1)
55
rails (~> 4.1)
66

77
GEM
@@ -74,7 +74,7 @@ GEM
7474
multi_json (~> 1.0)
7575
rack (~> 1.0)
7676
tilt (~> 1.1, != 1.3.0)
77-
sprockets-rails (2.2.2)
77+
sprockets-rails (2.2.4)
7878
actionpack (>= 3.0)
7979
activesupport (>= 3.0)
8080
sprockets (>= 2.8, < 4.0)
@@ -89,7 +89,7 @@ PLATFORMS
8989
ruby
9090

9191
DEPENDENCIES
92-
active_form!
92+
actionform!
9393
jquery-rails
9494
rake (~> 10.3.2)
9595
simple_form

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Active Form
1+
# Action Form
22

33
[![Build Status](https://api.travis-ci.org/rails/activeform.svg?branch=master)](https://travis-ci.org/rails/activeform)
44

5-
Set your models free from the `accepts_nested_attributes_for` helper. Active Form provides an object-oriented approach to represent your forms by building a form object, rather than relying on Active Record internals for doing this. Form objects provide an API to describe the models involved in the form, their attributes and validations. A form object deals with create/update actions of nested objects in a more seamless way.
5+
Set your models free from the `accepts_nested_attributes_for` helper. Action Form provides an object-oriented approach to represent your forms by building a form object, rather than relying on Active Record internals for doing this. Form objects provide an API to describe the models involved in the form, their attributes and validations. A form object deals with create/update actions of nested objects in a more seamless way.
66

77
## Installation
88

99
Add this line to your `Gemfile`:
1010

1111
```ruby
12-
gem 'active_form'
12+
gem 'actionform'
1313
```
1414

1515
## Defining Forms
1616

1717
Consider an example where you want to create/update a conference that can have many speakers which can present a single presentation with one form submission. You start by defining a form to represent the root model, `Conference`:
1818

1919
```ruby
20-
class ConferenceForm < ActiveForm::Base
20+
class ConferenceForm < ActionForm::Base
2121
self.main_model = :conference
2222

2323
attributes :name, :city
@@ -26,7 +26,7 @@ class ConferenceForm < ActiveForm::Base
2626
end
2727
```
2828

29-
Your form object has to subclass `ActiveForm::Base` in order to gain the necessary API. When defining the form, you have to specify the main_model the form represents with the following line:
29+
Your form object has to subclass `ActionForm::Base` in order to gain the necessary API. When defining the form, you have to specify the main_model the form represents with the following line:
3030

3131
```ruby
3232
self.main_model = :conference
@@ -35,14 +35,14 @@ self.main_model = :conference
3535
To add fields to the form, use the `attributes` or `attribute` class method. The form can also define validation rules for the model it represents. For the `presence` validation rule there is a short inline syntax:
3636

3737
```ruby
38-
class ConferenceForm < ActiveForm::Base
38+
class ConferenceForm < ActionForm::Base
3939
attributes :name, :city, required: true
4040
end
4141
```
4242

4343
## The API
4444

45-
The `ActiveForm::Base` class provides a simple API with only a few instance/class methods. Below are listed the instance methods:
45+
The `ActionForm::Base` class provides a simple API with only a few instance/class methods. Below are listed the instance methods:
4646

4747
1. `initialize(model)` accepts an instance of the model that the form represents.
4848
2. `submit(params)` updates the main form's model and nested models with the posted parameters. The models are not saved/updated until you call `save`.
@@ -80,10 +80,10 @@ class ConferencesController
8080
end
8181
```
8282

83-
Active Form will read property values from the model in setup. Given the following form class.
83+
Action Form will read property values from the model in setup. Given the following form class.
8484

8585
```ruby
86-
class ConferenceForm < ActiveForm::Base
86+
class ConferenceForm < ActionForm::Base
8787
attribute :name
8888
end
8989
```
@@ -101,7 +101,7 @@ Your `@conference_form` is now ready to be rendered, either do it yourself or us
101101
<% end %>
102102
```
103103

104-
Nested forms and collections can be easily rendered with `fields_for`, etc. Just use Active Form as if it would be an Active Model instance in the view layer.
104+
Nested forms and collections can be easily rendered with `fields_for`, etc. Just use Action Form as if it would be an Active Model instance in the view layer.
105105

106106
## Syncing Back
107107

@@ -143,7 +143,7 @@ If the `save` method returns false due to validation errors defined on the form,
143143

144144
## Nesting Forms: 1-n Relations
145145

146-
Active Form also gives you nested collections.
146+
Action Form also gives you nested collections.
147147

148148
Let's define the `has_many :speakers` collection association on the `Conference` model.
149149

@@ -157,7 +157,7 @@ end
157157
The form should look like this.
158158

159159
```ruby
160-
class ConferenceForm < ActiveForm::Base
160+
class ConferenceForm < ActionForm::Base
161161
attributes :name, :city, required: true
162162

163163
association :speakers do
@@ -172,7 +172,7 @@ This basically works like a nested `property` that iterates over a collection of
172172

173173
### has_many: Rendering
174174

175-
Active Form will expose the collection using the `speakers` method.
175+
Action Form will expose the collection using the `speakers` method.
176176

177177
```erb
178178
<%= form_for @conference_form |f| %>
@@ -201,7 +201,7 @@ end
201201
The full form should look like this:
202202

203203
```ruby
204-
class ConferenceForm < ActiveForm::Base
204+
class ConferenceForm < ActionForm::Base
205205
attributes :name, :city, required: true
206206

207207
association :speakers do
@@ -237,12 +237,12 @@ Use `fields_for` in a Rails environment to correctly setup the structure of para
237237

238238
## Dynamically Adding/Removing Nested Objects
239239

240-
Active Form comes with two helpers to deal with this functionality:
240+
Action Form comes with two helpers to deal with this functionality:
241241

242242
1. `link_to_add_association` will display a link that renders fields to create a new object.
243243
2. `link_to_remove_association` will display a link to remove a existing/dynamic object.
244244

245-
In order to use it you have to insert this line: `//= require active_form` to your `app/assets/javascript/application.js` file.
245+
In order to use it you have to insert this line: `//= require action_form` to your `app/assets/javascript/application.js` file.
246246

247247
In our `ConferenceForm` we can dynamically create/remove `Speaker` objects. To do that we would write in the `app/views/conferences/_form.html.erb` partial:
248248

@@ -324,7 +324,7 @@ And `app/views/conferences/_presentation_fields.html.erb` would be:
324324

325325
## Plain Old Ruby Object Forms
326326

327-
ActiveForm also can accept `ActiveModel::Model` instances as a model.
327+
ActionForm also can accept `ActiveModel::Model` instances as a model.
328328

329329
```ruby
330330
class Feedback
@@ -341,7 +341,7 @@ end
341341
The form should look like this.
342342

343343
```ruby
344-
class FeedbackForm < ActiveForm::Base
344+
class FeedbackForm < ActionForm::Base
345345
attributes :name, :body, :email, required: true
346346
end
347347
```

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require 'rdoc/task'
88

99
RDoc::Task.new(:rdoc) do |rdoc|
1010
rdoc.rdoc_dir = 'rdoc'
11-
rdoc.title = 'ActiveForm'
11+
rdoc.title = 'ActionForm'
1212
rdoc.options << '--line-numbers'
1313
rdoc.rdoc_files.include('README.rdoc')
1414
rdoc.rdoc_files.include('lib/**/*.rb')

active_form.gemspec renamed to actionform.gemspec

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
$:.push File.expand_path('../lib', __FILE__)
22

3-
require 'active_form/version'
3+
require 'action_form/version'
44

55
Gem::Specification.new do |s|
6-
s.name = 'active_form'
7-
s.version = ActiveForm::VERSION
6+
s.name = 'actionform'
7+
s.version = ActionForm::VERSION
88
s.authors = ['Petros Markou']
99
s.email = ['[email protected]']
10-
s.homepage = 'https://github.com/m-Peter/activeform'
10+
s.homepage = 'https://github.com/rails/actionform'
1111
s.summary = 'Create nested forms with ease.'
1212
s.description = 'An alternative layer to accepts_nested_attributes_for by using Form Models.'
1313
s.license = 'MIT'

lib/action_form.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ActionForm
2+
autoload :Base, 'action_form/base'
3+
autoload :Form, 'action_form/form'
4+
autoload :FormCollection, 'action_form/form_collection'
5+
autoload :FormDefinition, 'action_form/form_definition'
6+
autoload :TooManyRecords, 'action_form/too_many_records'
7+
autoload :ViewHelpers, 'action_form/view_helpers'
8+
autoload :FormHelpers, 'action_form/form_helpers'
9+
10+
class Engine < ::Rails::Engine
11+
initializer "action_form.initialize" do |app|
12+
ActiveSupport.on_load :action_view do
13+
include ActionForm::ViewHelpers
14+
end
15+
end
16+
end
17+
end

lib/active_form/base.rb renamed to lib/action_form/base.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
class Base
33
include ActiveModel::Model
44
include FormHelpers

lib/active_form/form.rb renamed to lib/action_form/form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
class Form
33
include ActiveModel::Validations
44
include FormHelpers

lib/active_form/form_collection.rb renamed to lib/action_form/form_collection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
class FormCollection
33
include ActiveModel::Validations
44

lib/active_form/form_definition.rb renamed to lib/action_form/form_definition.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
class FormDefinition
33
attr_accessor :assoc_name, :proc, :parent, :records
44

lib/active_form/form_helpers.rb renamed to lib/action_form/form_helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
module FormHelpers
33
ATTRIBUTES_KEY_REGEXP = /^(.+)_attributes$/
44

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
class TooManyRecords < RuntimeError
33
end
44
end
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module ActiveForm
1+
module ActionForm
22
VERSION = "0.0.1"
33
end

lib/active_form/view_helpers.rb renamed to lib/action_form/view_helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module ActiveForm
1+
module ActionForm
22
module ViewHelpers
33

44
def link_to_remove_association(name, f, html_options={})

lib/active_form.rb

-17
This file was deleted.

lib/rails/generators/form/form_generator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Rails
55
module Generators # :nodoc:
66
class FormGenerator < Rails::Generators::NamedBase # :nodoc:
7-
desc 'This generator creates an active form file at app/forms'
7+
desc 'This generator creates an action form file at app/forms'
88

99
check_class_collision suffix: 'Form'
1010

lib/rails/generators/form/form_install_generator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_forms_test_directory
2020
end
2121

2222
def include_js_file
23-
insert_into_file "app/assets/javascripts/application.js", "//= require active_form", :before => "//= require_tree ."
23+
insert_into_file "app/assets/javascripts/application.js", "//= require action_form", :before => "//= require_tree ."
2424
end
2525
end
2626
end

lib/rails/generators/form/templates/form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% module_namespacing do -%>
2-
class <%= class_name %>Form < ActiveForm::Base
2+
class <%= class_name %>Form < ActionForm::Base
33
<%- if attributes.present? -%>
44
attributes <%= attributes.map {|a| ":#{a.name}" }.join(", ") %>
55
<%- else -%>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# desc "Explaining what the task does"
2-
# task :active_form do
2+
# task :action_form do
33
# # Task goes here
44
# end

test/action_form_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class ActionFormTest < ActiveSupport::TestCase
4+
test "truth" do
5+
assert_kind_of Module, ActionForm
6+
end
7+
end

test/active_form_test.rb

-7
This file was deleted.

test/dummy/app/assets/javascripts/application.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
//
1313
//= require jquery
1414
//= require jquery_ujs
15-
//= require active_form
15+
//= require action_form
1616
//= require_tree .

test/dummy/app/forms/assignment_form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class AssignmentForm < ActiveForm::Base
1+
class AssignmentForm < ActionForm::Base
22
self.main_model = :assignment
33

44
attribute :name, required: true

test/dummy/app/forms/conference_form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ConferenceForm < ActiveForm::Base
1+
class ConferenceForm < ActionForm::Base
22
attributes :name, :city, required: true
33
attributes :photo
44

test/dummy/app/forms/project_form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ProjectForm < ActiveForm::Base
1+
class ProjectForm < ActionForm::Base
22
attributes :name, :description, :owner_id
33

44
association :tasks do

test/dummy/app/forms/song_form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class SongForm < ActiveForm::Base
1+
class SongForm < ActionForm::Base
22
attributes :title, :length, required: true
33

44
association :artist do

test/dummy/app/forms/survey_form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class SurveyForm < ActiveForm::Base
1+
class SurveyForm < ActionForm::Base
22
attribute :name, required: true
33

44
association :questions do

test/dummy/app/forms/user_form.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class UserForm < ActiveForm::Base
1+
class UserForm < ActionForm::Base
22
self.main_model = :user
33
attributes :name, :age, :gender, required: true
44

test/dummy/app/views/layouts/application.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Active Form Demo (using Simple Form)</title>
4+
<title>Action Form Demo (using Simple Form)</title>
55
<%= stylesheet_link_tag 'application', media: 'all' %>
66
<%= javascript_include_tag 'application' %>
77
<%= csrf_meta_tags %>
88
</head>
99
<body>
10-
<h1><%= link_to 'Active Form Demo', '#' %></h1>
10+
<h1><%= link_to 'Action Form Demo', '#' %></h1>
1111

1212
<div class="container">
1313
<%= yield %>

test/dummy/config/application.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rails/all'
44

55
Bundler.require(*Rails.groups)
6-
require "active_form"
6+
require "action_form"
77

88
module Dummy
99
class Application < Rails::Application

0 commit comments

Comments
 (0)