
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
A better way to show attributes
Add this line to your application's Gemfile:
gem 'data_display'
And then execute:
$ bundle
Run the generator:
$ rails generate data_display:install
At first, you need to add acts_as_displayable
in your models:
# For all attributes
class Product < ActiveRecord::Base
acts_as_displayable
end
Or:
# For some attributes
class Product < ActiveRecord::Base
acts_as_displayable :name, :description, :price, :active, :published_at
end
This generates the display methods to model attributes (eg [attribute] _display)
product = Product.new published_at: DateTime.now,
active: true,
title: nil,
price: 999990,
description: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus"
# Date, DateTime or Time
product.published_at_display
=> "December 10, 2012 11:58"
product.published_at_display :short
=> "10 Dec 11:58"
# YesClass or FalseClass
product.active_display
=> "Yes"
# String
product.content_display
=> "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ..."
product.content_display(:short)
=> "Lorem ipsum dolor sit amet, consectetuer adipiscing elit...."
# NilClass
product.title_display
=> "(empty)"
product.title_display(:short)
=> "-"
# Fixnum or Float
product.price_display
=> "9,999,990"
product.price_display(:currency)
=> "$9,999,990.00"
If you need to edit the format for dates or text, you can see the config/locales/data_display.en.yml (generated with rails g data_display:install
)
en:
data_display:
true_class:
formats:
long: 'Yes'
short: 'Yes'
false_class:
formats:
long: 'No'
short: 'No'
nil_class:
formats:
long: '(empty)'
short: '-'
time:
formats:
long: ! '%B %d, %Y %H:%M'
short: ! '%d %b %H:%M'
date_time:
formats:
long: ! '%B %d, %Y %H:%M'
short: ! '%d %b %H:%M'
date:
formats:
long: ! '%B %d, %Y'
short: ! '%b %d'
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that data_display 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
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.