enum_help 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -4
- data/lib/enum_help/simple_form.rb +3 -1
- data/lib/enum_help/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da7e2ccf08926cc86540d06e331f2bfe82c71634
|
4
|
+
data.tar.gz: f17dc5c72314bcc6551d68e3d737cdda82de0d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9266b252cbb1087318c363a7bba5617418060071f3063268ca61c91aab464440aafb5aad6049b066d86d58e1c2fa3545741f09856791a4eee8a73fb3086c1b5c
|
7
|
+
data.tar.gz: fd97e84192133b762a65e4bed61c2dda446aa067a9547d741ddc2c3b03c56a61d3169c717045625baac452786ef75c90a22518e24b51d3beb5680539591df64e
|
data/README.md
CHANGED
@@ -31,7 +31,11 @@ required Rails 4.1.x
|
|
31
31
|
In model file:
|
32
32
|
|
33
33
|
class Order < ActiveRecord::Base
|
34
|
-
enum status: { "nopayment" => 0, "finished" => 1 }
|
34
|
+
enum status: { "nopayment" => 0, "finished" => 1, "failed" => 2, "destroyed" => 3 }
|
35
|
+
|
36
|
+
def self.restricted_statuses
|
37
|
+
statuses.except :failed, :destroyed
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
You can call:
|
@@ -40,8 +44,8 @@ You can call:
|
|
40
44
|
order.update_attribute :status, 0
|
41
45
|
order.status
|
42
46
|
# > nopayment
|
43
|
-
order.status_i18n
|
44
|
-
# >
|
47
|
+
order.status_i18n # if you have an i18n file defined as following, it will return "未支付".
|
48
|
+
# > 未支付
|
45
49
|
|
46
50
|
In _form.html.erb using simple form:
|
47
51
|
|
@@ -49,6 +53,12 @@ In _form.html.erb using simple form:
|
|
49
53
|
|
50
54
|
This will generate select field with translations automaticlly.
|
51
55
|
|
56
|
+
And if you want to generate select except some values, then you can pass a collection option.
|
57
|
+
|
58
|
+
<%= f.input :status Order.restricted_statuses %>
|
59
|
+
|
60
|
+
|
61
|
+
|
52
62
|
Other arguments for simple_form are supported perfectly.
|
53
63
|
|
54
64
|
e.g.
|
@@ -67,10 +77,12 @@ I18n local file example:
|
|
67
77
|
status:
|
68
78
|
finished: 完成
|
69
79
|
nopayment: 未支付
|
70
|
-
|
80
|
+
failed: 失败
|
81
|
+
destroyed: 已删除
|
71
82
|
|
72
83
|
## Thanks
|
73
84
|
* [mrhead](https://github.com/mrhead)
|
85
|
+
* [Jin Lee](https://github.com/neojin)
|
74
86
|
|
75
87
|
## Contributing
|
76
88
|
|
@@ -16,7 +16,9 @@ module EnumHelp
|
|
16
16
|
|
17
17
|
def initialize(*args)
|
18
18
|
super
|
19
|
-
|
19
|
+
enum = input_options[:collection] || @builder.options[:collection]
|
20
|
+
raise "Attribute '#{attribute_name}' has no enum class" unless enum ||= object.class.send(attribute_name.to_s.pluralize)
|
21
|
+
|
20
22
|
collect = enum.collect{|k,v| [::I18n.t("enums.#{object.class.to_s.underscore}.#{attribute_name}.#{k}", default: k),k] }
|
21
23
|
# collect.unshift [args.last[:prompt],''] if args.last.is_a?(Hash) && args.last[:prompt]
|
22
24
|
|
data/lib/enum_help/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_help
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lester Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|