dejavu 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +16 -2
  2. data/lib/dejavu/version.rb +1 -1
  3. data/lib/dejavu.rb +11 -3
  4. metadata +11 -11
data/README.md CHANGED
@@ -2,7 +2,7 @@ Dejavu
2
2
  ======
3
3
 
4
4
  Dejavu is a very small piece of software which lets you remember your object
5
- state after a failed POST action usign redirect. A typical Rails controller
5
+ state after a failed POST action using redirect. A typical Rails controller
6
6
  `create` action looks like this:
7
7
 
8
8
  ```
@@ -45,7 +45,7 @@ Usage
45
45
  =====
46
46
 
47
47
  If you want to use Dejavu, simply add a `save_for_dejavu` call in the
48
- controller:
48
+ controller and issue a redirect instead of a render:
49
49
 
50
50
  respond_to do |format|
51
51
  if @product.save
@@ -65,6 +65,20 @@ Then, in the view load the object in the form usign the `get_dejavu_for`:
65
65
  <% end %>
66
66
 
67
67
 
68
+ Nested Attributes
69
+ -----------------
70
+
71
+ You can also use dejavu to recreate a one-to-one associated model in your
72
+ form. To do so you must tell dejavu which association to save in the
73
+ controller:
74
+
75
+ save_for_dejavu @product, :nested => :prices
76
+
77
+ This will assume you have a `Product` class which has a `:has_one` association
78
+ to a `Price` class.
79
+
80
+
81
+
68
82
  Final notes
69
83
  ===========
70
84
 
@@ -1,3 +1,3 @@
1
1
  module Dejavu
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/dejavu.rb CHANGED
@@ -13,7 +13,11 @@ module Dejavu
13
13
 
14
14
  if has_dejavu?(obj)
15
15
  foo = if is_instance
16
- obj.attributes = flash[:"saved_#{model_name}_for_redisplay"]
16
+ if Rails::VERSION::MINOR >= 1
17
+ obj.assign_attributes(flash[:"saved_#{model_name}_for_redisplay"], :without_protection => true)
18
+ else
19
+ obj.attributes = flash[:"saved_#{model_name}_for_redisplay"]
20
+ end
17
21
  obj
18
22
  else
19
23
  obj.to_s.classify.constantize.new flash[:"saved_#{model_name}_for_redisplay"]
@@ -27,8 +31,12 @@ module Dejavu
27
31
  end
28
32
 
29
33
  module ControllerMethods
30
- def save_for_dejavu(obj)
31
- flash[:"saved_#{obj.class.model_name.underscore}_for_redisplay"] = obj.attributes
34
+ def save_for_dejavu(obj, opts = {})
35
+ attrs = obj.attributes
36
+ if opts[:nested]
37
+ attrs["#{opts[:nested]}_attributes"] = obj.send(opts[:nested]).attributes
38
+ end
39
+ flash[:"saved_#{obj.class.model_name.underscore}_for_redisplay"] = attrs
32
40
  end
33
41
  end
34
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dejavu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-27 00:00:00.000000000 Z
12
+ date: 2012-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &82986950 !ruby/object:Gem::Requirement
16
+ requirement: &79731040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *82986950
24
+ version_requirements: *79731040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &82985980 !ruby/object:Gem::Requirement
27
+ requirement: &79730230 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *82985980
35
+ version_requirements: *79730230
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: capybara
38
- requirement: &82985210 !ruby/object:Gem::Requirement
38
+ requirement: &79728920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.1.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *82985210
46
+ version_requirements: *79728920
47
47
  description: Remember your object after a redirect
48
48
  email:
49
49
  - roger@itnig.net
@@ -139,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  segments:
141
141
  - 0
142
- hash: -960683919
142
+ hash: -399023693
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  none: false
145
145
  requirements:
@@ -148,10 +148,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: -960683919
151
+ hash: -399023693
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 1.8.10
154
+ rubygems_version: 1.8.15
155
155
  signing_key:
156
156
  specification_version: 3
157
157
  summary: Remember your object after a redirect