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.
- checksums.yaml +4 -4
- data/README.md +23 -6
- data/lib/pre_render/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e072582c9529942abe36c58341c2d277674e7b6
|
4
|
+
data.tar.gz: d8b8c39f4fafcb8a2e94f2ed09e683050a95a5c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
64
|
-
fully initialize any instance variables a view might need to render itself. If you are using
|
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
|
70
|
-
|
71
|
-
|
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
|
|
data/lib/pre_render/version.rb
CHANGED