0.0
No release in over a year
A gem that enhances the Rails dom_id helper method, allowing it to accept multiple ActiveRecord models or custom strings as arguments.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
>= 0
~> 13.0
~> 3.0
 Project Readme

DomIdNested

DomIdNested is a Ruby on Rails gem that extends the functionality of the built-in dom_id helper, making it more versatile by allowing it to work with a combination of ActiveRecord models and custom strings.

Installation

Add this line to your application's Gemfile:

gem "dom_id_nested"

And then execute:

$ bundle install

Usage

With DomIdNested, you can easily generate DOM IDs by passing a combination of ActiveRecord models and custom strings to the dom_id helper. Here’s an example:

user = User.find(1)

dom_id(user, "edit_button") #=> "user_1_edit_button"

You can also pass multiple ActiveRecord models and strings as arguments:

post = Post.find(1)
comment = Comment.find(2)

dom_id(user, post, comment, "content") #=> "user_1_post_1_comment_2_content"

The gem will automatically omit any blank records passed:

dom_id(user, nil, "", "edit_button") #=> "user_1_edit_button"

If all records are blank, the dom_id helper will return nil:

dom_id(nil, "") #=> nil

License

The gem is available as open source under the terms of the MIT License » https://opensource.org/licenses/MIT.