translateable 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aeb41f65842e0bad160968db1710b45da49c12619b6e705526014fa99038bbf3
4
- data.tar.gz: fddb74f188f3ecfe4d9abe94a43199f019510d8deb64fbba08706c1e449e632f
3
+ metadata.gz: 2b40a753c044fe858f9b958b677ca58bd082f5fbdcb3f0862299ce12db189333
4
+ data.tar.gz: c4c894a4d59f088a3b64761d09a92df27ccd9a0dba11f822da5ca323002c44e6
5
5
  SHA512:
6
- metadata.gz: fdcbcbd924443fac434c66ea35a8df53928c61a4e58d83868d74c6711195457c07c4619cb324ec47d0ace9f047168a10d17f43eebbb0dc6d81934d422a7aa5b6
7
- data.tar.gz: dc66c4efaf4ec49d590bf739b09b71bea0dc583e60709520634d2b9314d1ac4975275365570a975c8288ac9f0c4065a44e99793297444465a699a045b2244b08
6
+ metadata.gz: 2a313c4d934d22adda7cf0cc78edc6d7f00bb282a7b8a6b6b687780892e54a4327a60155a2917a51838a7443ffd75b7a78bd1875119c2f8ad4452dd1944f7486
7
+ data.tar.gz: 77e78c607e1b5b5c8dbfa7b8b3f2b7b32c734439ec1946fa98daa08672d3dcd2609c8720535200fa30d82539352eb16bfa1921312ec011a2abcdec7e0372e36b
data/README.md CHANGED
@@ -140,6 +140,12 @@ end
140
140
  ```
141
141
  Now you can add/delete/update the `title` attribute value in different languages via a single form.
142
142
 
143
+ A plain field works too and edits the current locale's text, also when the form is re-rendered after a failed validation:
144
+ ```haml
145
+ = form_for @post do |f|
146
+ = f.text_field :title
147
+ ```
148
+
143
149
  ### Migration
144
150
 
145
151
  Attributes must exist with the `JSONB` type in the database, so create a migration:
@@ -1,3 +1,3 @@
1
1
  module Translateable
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
data/lib/translateable.rb CHANGED
@@ -76,6 +76,13 @@ module Translateable
76
76
  define_method("#{attr}=") do |arg|
77
77
  self[attr] = arg.respond_to?(:to_hash) ? arg.to_hash : (self[attr] || {}).merge(I18n.locale.to_s => arg)
78
78
  end
79
+
80
+ # Rails form helpers read <attr>_before_type_cast for user-assigned values, e.g. when
81
+ # re-rendering a form after a failed validation. Without this they would show the raw
82
+ # JSONB hash instead of the current locale's text (#10).
83
+ define_method("#{attr}_before_type_cast") do
84
+ send(attr)
85
+ end
79
86
  end
80
87
  end
81
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translateable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Antonyan