pre_render 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -6
  3. data/lib/pre_render/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3476896a3dfcf2a171a65e3f6e52baf0457000e
4
- data.tar.gz: 5ce05cbe2b9f9d80f6afb66be37bb4f76853a26f
3
+ metadata.gz: 0e072582c9529942abe36c58341c2d277674e7b6
4
+ data.tar.gz: d8b8c39f4fafcb8a2e94f2ed09e683050a95a5c1
5
5
  SHA512:
6
- metadata.gz: 295e79ae45cf471552f0016e96bba3a433da627da0cb4764aebce5c84b00ea85e50061ba3e4398bd144784b022e59cb1a22ac38e21b6b54ceb8261a8ba0ed26b
7
- data.tar.gz: 2c56548248bca50c19494f19036a59318eff675154b383c9634382be81536d741c90c7b5448a40927e5fe3c7170670523aae81d114a47e0b84ff2ffce626621a
6
+ metadata.gz: 0b1f47fba0855065a07e3f23e638421a8abd7fe3bc8d1399c8f3fa239e6d1deb355c965fab24f544b0083cc4dfb1d6e1ee0078897a42bccef761e5ab50a2baf6
7
+ data.tar.gz: cb264f0ad4ff5359d95fad28f1a58a11d64bf8386c095c9d1e66d9499f3638548b152e6b872fb4c8691d8b206242dcdd4dd654b412eecba3472f0e6ddce9a707
data/README.md CHANGED
@@ -43,6 +43,7 @@ class PeopleController < ApplicationController
43
43
  when :edit
44
44
  # ...
45
45
  # ...
46
+ end
46
47
  end
47
48
 
48
49
  private
@@ -60,15 +61,31 @@ class PeopleController < ApplicationController
60
61
  end
61
62
  ```
62
63
 
63
- The ```pre_render()``` method will be called right before Rails' ```render()``` method. This will give your controller a last chance to
64
- fully initialize any instance variables a view might need to render itself. If you are using any view model construct, this is a
65
- good place to initialize or finish initializing it.
64
+ The ```pre_render()``` method will be called right before Rails' ```render()``` method. This will give your controller a last chance
65
+ to fully initialize any instance variables a view might need to render itself. If you are using some sort of view model or
66
+ presenter construct, this is a good place to initialize or finish initializing it.
67
+
68
+ The usefulness of this construct becomes apparent when validation comes into play. Suppose your ```Person``` model looks like this:
69
+
70
+ ```ruby
71
+ class Person < ActiveRecord::Base
72
+ validates :first_name, presence: true
73
+ validates :last_name, presence: true
74
+ validates :age, presence: true
75
+ end
76
+ ```
77
+
78
+ When someone goes to create a new ```Person``` record, but forgets to enter a required field and hits the ```Create``` button,
79
+ ```PeopleController#create()``` will refuse to create the record due to failed validation. At that point, the controller will want
80
+ to render the ```new``` view once more, even though the ```action_name``` is ```create```. Except this time when ```pre_render()```
81
+ is called, the ```view``` argument will rightly be ```:new```, allowing you to do whatever is needed to ensure the view
82
+ renders successfully.
66
83
 
67
84
  ## Credits
68
85
 
69
- The idea for this gem came from my time spent working as a classic ASP.NET developer. The classic ASP.NET page event model
70
- also supports the notion of a ```PreRender()``` method being called right before the ```Render()``` method to allow an application's
71
- code-behind class to finish initialization of its properties and fields.
86
+ The idea for this gem came from my time spent working as a classic ASP.NET developer. The ASP.NET Page Event model supports the
87
+ notion of a ```PreRender()``` method being called right before the ```Render()``` method to allow an application's code-behind
88
+ class to finish initialization of its properties and fields.
72
89
 
73
90
  I found this to be useful then, as I do now in the Rails world.
74
91
 
@@ -1,3 +1,3 @@
1
1
  module PreRender
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre_render
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Brazil