New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

active_model-inherited_partials

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

active_model-inherited_partials

  • 0.1.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Rails partials

Rails partials are great when it comes to rendering a model. But they still seem to have inconsistencies and a room for further improvements.

Consider the following example: we have a model inheritance chain like Message → Message::Text → Message::HTML.

Issue #1: your code gets WET

To render both text and HTML messages we need to define both message/texts/text & message/htmls/html partials — even when they are identical and just rendering message.title and message.body.

Issue #2: inconsistent variable naming

In the above case we get text & html variables inside the partials, while it's just message for the basic messages/message one. You can't even copy the identical code from one partial into another!

Issue #3: inconsistent paths

Both texts & HTML end up in views/message, while the basic message goes to views/messages. Thus we get two directories instead of one.

So, meet

Inherited Partials

This Rails Engine brings you:

  1. Nesting directories to respect model namespaces.
  2. Consistent variable naming in namespaced partials.
  3. Inheritance when a partial is missing.

It provides the above example case with the following partial paths:

messages/message
messages/text/message
messages/html/message

When a model's partial is missing, the parent's one is looked up, upto the basic one.

Usage

No explicit code nor configuration needed, just install it!

Installation

Add this line to your application's Gemfile:

gem "active_model-inherited_partials"

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_model-inherited_partials

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 28 Jun 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc