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 +4 -4
- data/README.md +6 -0
- data/lib/translateable/version.rb +1 -1
- data/lib/translateable.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b40a753c044fe858f9b958b677ca58bd082f5fbdcb3f0862299ce12db189333
|
|
4
|
+
data.tar.gz: c4c894a4d59f088a3b64761d09a92df27ccd9a0dba11f822da5ca323002c44e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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:
|
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
|