acts_as_multipart_form 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  == unreleased changes
2
2
 
3
+ == 0.0.13
4
+
5
+ * Major documentation updates
6
+ * Added attr_accessible to the InProgressForm model for rails 3.2 compatibility
7
+ * Updated failing tests
8
+
3
9
  == 0.0.12
4
10
 
5
11
  * Fixed an issue where a symbol was used as the value in a where clause, causing rails 3.1 to freak out.
@@ -4,25 +4,45 @@ Create multipart forms in rails without using multiple routes. A controller mix
4
4
 
5
5
  = How to use
6
6
 
7
- == Install the gem with
7
+ == Add the gem to your gemfile
8
8
 
9
- gem install acts_as_multipart_form
9
+ gem "acts_as_multipart_form"
10
10
 
11
- == Install the migration and config with
11
+ == Install the migration and config
12
12
 
13
13
  rails generate acts_as_multipart_form:install
14
+ rake db:migrate
14
15
 
15
- == Add the mixin to your controller
16
+ == Add the mixin and methods to your controller
16
17
 
17
- acts_as_multipart_form :name => :hire_form, :parts => [:person_info, :job_info], :model => "Person", :form_route => "person_hire_form"
18
+ PeopleController < ApplicationController
19
+ acts_as_multipart_form :name => :hire_form, :parts => [:personal, :job]
18
20
 
19
- The parts correspond to methods in the controller and partials in the controller's views folder. Additional methods called :person_info_update and :job_info_update are also necessary to handle saving the data.
21
+ def hire_form
22
+ @form_subject.multipart_form_controller_action = params[:multipart_form_part]
23
+ end
20
24
 
21
- Each form has a polymorphic relationship with a single record. This relationship is specified by the model key's value. This is how the form is loaded on the index page and the only association it has with the rest of the system.
25
+ def personal
26
+ end
22
27
 
23
- Two routes can be specified for the form system. The form route corresponds to the route to the form itself. It's default value is model_name_form_name. In the example, the specified value would be the default value. The show route, specified with the tag :show_route is redirected to after the last part of the multipart form is submitted and passes validations. It defaults to model_name to correspond with the model's view page.
28
+ def personal_update
29
+ return { valid: @form_subject.update_attributes(params[:person])}
30
+ end
24
31
 
25
- Note that when you add the route to your route file, it must be able to match both get and post requests.
32
+ def job
33
+ end
34
+
35
+ def job_update
36
+ return { valid: @form_subject.update_attributes(params[:person])}
37
+ end
38
+
39
+ This example splits the fields for the Person model across two parts.
40
+
41
+ Each part needs two methods for the displayed form and data update steps. The data update steps need to return a hash with the key valid set to true or false. If part based validations are needed, the controller action must be set. It can be done in either the main action, hire_form, or only on the actions that need it.
42
+
43
+ Each form has a polymorphic relationship with a single record. This relationship is specified by the model key's value. This is how the form is loaded on the index page and the only association it has with the rest of the system. The record is stored in the @form_subject variable.
44
+
45
+ See MultipartFormInController for additional documentation.
26
46
 
27
47
  == Add the mixin to your model
28
48
 
@@ -30,19 +50,41 @@ Note that when you add the route to your route file, it must be able to match bo
30
50
 
31
51
  This is currently only used for validations. If this is set, you can use a validation like this to only validate a field if the save is coming from a specific multipart form part.
32
52
 
33
- validates_presence_of :name, :if => :hire_form_personal_info?
53
+ validates_presence_of :name, :if => :hire_form_personal_update?
54
+
55
+ == Add the route
56
+
57
+ resources :people do
58
+ match 'edit', to: 'people#hire_form', :via => [:get, :post]
34
59
 
35
60
  == Setting up your form
36
61
 
37
- <%= render "multipart_form/breadcrumb" %>
62
+ These examples use formtastic but it is not required.
63
+
64
+ app/views/people/hire_form.html.erb:
65
+
66
+ <%= render :partial => "multipart_form/breadcrumb" %>
38
67
 
39
- <%= form_for @form_subject, :url => person_hire_form_path(:id => @form_subject.id, :multipart_form_part => @next_multipart_form_part), :html => {:method => :post} do |f| %>
40
- <%= render "multipart_form/all_errors" %>
41
- <%= render @multipart_form_part, :locals => {:form => f} %>
68
+ <%= semantic_form_for @form_subject, :url => person_hire_form_path(:id => @form_subject.id, :multipart_form_part => @next_multipart_form_part), :html => { :method => :post } do |f| %>
69
+ <%= f.semantic_errors %>
70
+ <%= render :partial => @multipart_form_part, :locals => {:form => f} %>
42
71
  <%= f.submit "Submit" %>
43
72
  <% end %>
44
73
 
45
- The breadcrumb adds links to the other multipart for parts. The all_errors partial is a substitute for putting error handling on each individual partial. The url and @form_subject instance variable are necessary to make the form submit and redirect correctly.
74
+ app/views/people/_personal.html.erb:
75
+
76
+ <%= form.inputs do %>
77
+ <%= form.input :name %>
78
+ <%= form.input :address %>
79
+ <% end %>
80
+
81
+ app/views/people/_job.html.erb:
82
+
83
+ <%= form.inputs do %>
84
+ <%= form.input :hire_date %>
85
+ <%= form.input :salary %>
86
+ <% end %>
87
+
46
88
  == Adding form part links to the index page
47
89
 
48
90
  === On the controller
@@ -56,7 +98,6 @@ The breadcrumb adds links to the other multipart for parts. The all_errors part
56
98
 
57
99
  Creates links to each form part for the given form subject. The load_multipart_form_index_links must be called to load the data for the links. The configuration options in the initializer can be used to change the output of the partial.
58
100
 
59
-
60
101
  == Future work
61
102
 
62
103
  * Fix the index links loading so that the user does not have to explicitly call a method when they are needed
@@ -78,4 +119,3 @@ Creates links to each form part for the given form subject. The load_multipart_
78
119
 
79
120
  Copyright (c) 2011 Jeremiah Hemphill. See LICENSE.txt for
80
121
  further details.
81
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "acts_as_multipart_form"
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremiah Hemphill", "Ethan Pemble"]
12
- s.date = "2012-04-10"
12
+ s.date = "2012-05-09"
13
13
  s.description = "Multipart forms using custom routes"
14
14
  s.email = "jeremiah@cloudspace.com"
15
15
  s.extra_rdoc_files = [
@@ -102,7 +102,7 @@ Gem::Specification.new do |s|
102
102
  "spec/dummy/script/rails",
103
103
  "spec/in_progress_form_spec.rb",
104
104
  "spec/integration/navigation_spec.rb",
105
- "spec/multipart_form_in_controller_integeration_spec.rb",
105
+ "spec/multipart_form_in_controller_integration_spec.rb",
106
106
  "spec/multipart_form_in_controller_spec.rb",
107
107
  "spec/multipart_form_in_model_integration_spec.rb",
108
108
  "spec/multipart_form_in_model_spec.rb",
@@ -12,6 +12,8 @@ module MultipartForm
12
12
  set_table_name "multipart_form_in_progress_forms"
13
13
  belongs_to :form_subject, :polymorphic => true
14
14
 
15
+ attr_accessible :form_subject, :form_subject_id, :form_subject_type, :form_name, :last_completed_step, :completed
16
+
15
17
  validates_presence_of :form_subject
16
18
  validates_presence_of :form_name
17
19
  validates_presence_of :last_completed_step
@@ -2,39 +2,22 @@ class PeopleController < ApplicationController
2
2
  acts_as_multipart_form :name => :hire_form, :parts => [:person_info, :job_info], :model => "Person", :form_route => "person_hire_form"
3
3
 
4
4
  def person_info
5
- @person = Person.find(params[:id])
6
5
  end
7
6
 
8
7
  def person_info_update
9
- @person = Person.find(params[:id])
10
- @person.multipart_form_controller_action = "person_info_update"
11
- if params[:person] and params[:person][:person]
12
- @person.update_attributes(params[:person][:person])
13
- return { :valid => @person.valid? }
14
- else
15
- return { :valid => false }
16
- end
17
-
8
+ @form_subject.multipart_form_controller_action = "person_info_update"
9
+ return { :valid => @form_subject.update_attributes(params[:person]) }
18
10
  end
19
11
 
20
12
  def job_info
21
- @person = Person.find(params[:id])
22
13
  end
23
14
 
24
15
  def job_info_update
25
- @person = Person.find(params[:id])
26
- @person.multipart_form_controller_action = "job_info_update"
27
- if @person.update_attributes(params[:person])
28
- return {:valid => true}
29
- else
30
- return {:valid => false }
31
- end
16
+ @form_subject.multipart_form_controller_action = "job_info_update"
17
+ return { :valid => @form_subject.update_attributes(params[:person]) }
32
18
  end
33
19
 
34
20
  def hire_form
35
- #puts "stub method for the hire form"
36
- #@person = Person.find(params[:id])
37
-
38
21
  respond_to do |format|
39
22
  format.html
40
23
  end
@@ -1,5 +1,7 @@
1
1
  class Person < ActiveRecord::Base
2
2
  multipart_formable :forms => [:hire_form]
3
3
 
4
+ attr_accessible :name
5
+
4
6
  validates_presence_of :name, :if => :hire_form_person_info_update?
5
7
  end
@@ -3,6 +3,6 @@
3
3
  </p>
4
4
 
5
5
  <div class="field">
6
- <%= locals[:form].label :name %><br />
7
- <%= locals[:form].text_field :name %>
6
+ <%= form.label :name %><br />
7
+ <%= form.text_field :name %>
8
8
  </div>
@@ -2,7 +2,7 @@
2
2
  This is the personal info multipart form partial.
3
3
  </p>
4
4
 
5
- <%= locals[:form].fields_for @person do |fp| %>
6
- <%= fp.label :name %><br />
7
- <%= fp.text_field :name %>
8
- <% end %>
5
+ <div class="field">
6
+ <%= form.label :name %><br />
7
+ <%= form.text_field :name %>
8
+ </div>
@@ -2,10 +2,10 @@
2
2
  This is the hire form view
3
3
  </p>
4
4
 
5
- <%= render "multipart_form/breadcrumb" %>
5
+ <%= render :partial => "multipart_form/breadcrumb" %>
6
6
 
7
7
  <%= form_for @form_subject, :url => person_hire_form_path(:id => @form_subject.id, :multipart_form_part => @next_multipart_form_part), :html => {:method => :post} do |f| %>
8
- <%= render "multipart_form/all_errors" %>
9
- <%= render @multipart_form_part, :locals => {:form => f} %>
8
+ <%= render :partial => "multipart_form/all_errors" %>
9
+ <%= render :partial => @multipart_form_part, :locals => {:form => f} %>
10
10
  <%= f.submit "Submit" %>
11
11
  <% end %>
@@ -4,7 +4,7 @@ Feature: I should be able to see error messages
4
4
  Given there are no People in the system
5
5
  And a person with an incomplete multipart form exists
6
6
  When I go to the person hire_form page for that person
7
- And I fill in "person_person_name" with ""
7
+ And I fill in "person_name" with ""
8
8
  And I press "Submit"
9
9
  Then I should see "1 error prohibited this form from being saved:"
10
10
  And I should see "Person: Name can't be blank"
@@ -13,7 +13,7 @@ Feature: I should be able to see error messages
13
13
  Given there are no People in the system
14
14
  And a person with an incomplete multipart form exists
15
15
  When I go to the person hire_form page for that person
16
- And I fill in "person_person_name" with "Jeremiah"
16
+ And I fill in "person_name" with "Jeremiah"
17
17
  And I press "Submit"
18
18
  Then I should not see "0 errors prohibited this form from being saved:"
19
19
  And I should not see "Person: Name can't be blank"
@@ -8,7 +8,7 @@ Feature: I should be able to submit data using the multipart form system
8
8
  Given there are no People in the system
9
9
  And a person with an incomplete multipart form exists
10
10
  When I go to the person hire_form page for that person
11
- And I fill in "person_person_name" with "Ethan"
11
+ And I fill in "person_name" with "Ethan"
12
12
  And I press "Submit"
13
13
  Then that person's information should have updated
14
14
  And I should be on the person hire_form page
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_multipart_form
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremiah Hemphill
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-04-10 00:00:00 Z
14
+ date: 2012-05-09 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -240,7 +240,7 @@ files:
240
240
  - spec/dummy/script/rails
241
241
  - spec/in_progress_form_spec.rb
242
242
  - spec/integration/navigation_spec.rb
243
- - spec/multipart_form_in_controller_integeration_spec.rb
243
+ - spec/multipart_form_in_controller_integration_spec.rb
244
244
  - spec/multipart_form_in_controller_spec.rb
245
245
  - spec/multipart_form_in_model_integration_spec.rb
246
246
  - spec/multipart_form_in_model_spec.rb
@@ -258,7 +258,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
258
  requirements:
259
259
  - - ">="
260
260
  - !ruby/object:Gem::Version
261
- hash: -704243925010258065
261
+ hash: 1196884223902992685
262
262
  segments:
263
263
  - 0
264
264
  version: "0"