You can't change se separator. It is hard-coded into Rails.
For example, post_554 is generated by the dom_id
helper, which internally relies on the RecordIdentifier
class.
Here's the definition.
def dom_id(record, prefix = nil)
if record_id = record.id
"#{dom_class(record, prefix)}#{JOIN}#{record_id}"
else
dom_class(record, prefix || NEW)
end
end
The separator, the JOIN
constant, is defined as freezed String so you can't change it.
module RecordIdentifier
extend self
JOIN = '_'.freeze
NEW = 'new'.freeze
There are two ways to change it:
- Create your own helper (suggested)
- Overwrite the existing methods/helpers with your own implementations (not suggested)
There are also some technical restrictions that explain the reason behind this choice, mainly tied to the language behind Rails.
For instance, talking about symbols
:post_554 # valid symbol
:post-554 # invalid symbol
:"post-554" # valid symbol
Using -
would probably require a less cleaner approach to Ruby.
Personally, I prefer using -
rather than _
and I tend to avoid standard Rails helpers unless strictly required.