AttributesFor
ActiveView Helper to present formatted ActiveModel attributes with icons.
Installation
Add this line to your application's Gemfile:
gem 'attributes_for'
And then execute:
$ bundle
Or install it yourself as:
$ gem install attributes_for
Run generator to add I18n locales:
$ rails generate attributes_for:install
Screenshot

Usage
Present attributes using the API in the example below. It can also generate a
standard label value pair given an attribute name using the attribute method. Arbitrary
strings can also be presented using the string method.
<ul class="list-unstyled">
<%= attributes_for @company do |b| %>
<li><%= b.attribute :name, class: 'fa fa-building-o' %></li>
<li><%= b.phone :phone %></li>
<li><%= b.phone :fax, class: 'fa fa-fax' %></li>
<li><%= b.email :email %></li>
<li><%= b.email :support_email %></li>
<li><%= b.url :website, id: :site %></li>
<li>
<%= b.attribute(:user, class: 'fa fa-user') do %>
<%= link_to @company.user_name, url_for(@company.user) %>
<% end %>
</li>
<li><%= b.duration :duration %></li>
<li><%= b.boolean :active %></li>
<li><%= b.date :created_at, format: :long %> </li>
<% end %>
</ul>
Options
Available options:
- :label - Disables label if set to false
- :css - Override element's CSS
- :id - Set element's ID
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/blacktangent/attributes_for. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.