Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Help ActiveRecord::Enum feature to work fine with I18n.
As you know in Rails 4.1.0 , ActiveRecord supported Enum method. But it doesn't work fine with I18n
This gem can help you work fine with Enum and I18n
Add this line to your application's Gemfile:
gem 'enum_i18n_helper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install enum_i18n_helper
Required Rails 4.1.x
In model file:
class Order < ActiveRecord::Base
enum status: { "nopayment" => 0, "finished" => 1, "failed" => 2, "destroyed" => 3 }
def self.restricted_statuses
statuses.except :failed, :destroyed
end
end
You can call:
order = Order.first
order.update_attribute :status, 0
order.status
# > nopayment
order.status_i18n # if you have an i18n file defined as following, it will return "未支付".
# > 未支付
You can also fetch the translated enum collection, if you need to:
Order.statuses_i18n
I18n local file example:
# config/locales/model/order.zh-cn.yml
zh-cn:
enums:
order:
status:
finished: 完成
nopayment: 未支付
failed: 失败
destroyed: 已删除
If you want to use enum feature, field of your table can't be named with reference
.
When it is named with 'reference' and define enum in model file, there will be raised an error as below:
NoMethodError: super: no superclass method `enum' for...
Thanks for all the contributors.
git checkout -b my-new-feature
)rspec
git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that enum_i18n_helper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.