![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
has_money_fields
is a try to DRY the following code from the Money gem
documentation
composed_of :price,
:class_name => "Money",
:mapping => [%w(price_cents cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
It turns that code it into a smal gem that you can use yo provide currency capabilities to fields on your ActiveRecord models.
You can choose whether to store the currency with you "money" or to leave it to
the default you've configured for the gem. For an example Product
model:
You'll need a migration like this:
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.integer :money_price, :default => 0
t.string :currency_price
t.string :name, :null => false
end
end
def self.down
drop_table :products
end
end
And a model like that:
class Product < ActiveRecord::Base
has_money_fields :price
end
money_price
will store the amount and 'currency_price' will store the actual
currency, so, at the end your product will have a price
field that you can
use like that:
p = Product.new :price => Money.new(1000, "EUR"), :name => "T-shirt"
p.price # => #<Money cents:1000 currency:EUR>
p.price.format # => "10.00 €"
p.price.cents # => 1000
p.price.currency_as_string # => "€"
To use the default currency from the money gem, you'd rather drop the
currency_price
field from the migration and use has_money_fields
like that:
class Product < ActiveRecord::Base
has_money_fields :price, :only_cents => true
end
You can use ActiveRecord validations, as the following example:
class Product < ActiveRecord::Base
has_money_fields :price
validates :price, :presence => true
end
product = Product.new :price => nil
product.save # => false
product.valid? # => false
FAQs
Unknown package
We found that has_money_fields demonstrated a not healthy version release cadence and project activity because the last version was released 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.