I simply began looking at Wordpress' CSS Architecture to review a method that's established and pretty effective to understand better HTML habits. I have observed they will use all hyphens - (post-554 for instance), while Rails uses underscores _ (post_554 for instance). I am wondering if there's some setting to personalize this in Rails, something similar to ActionView::Template.word_boundary = "-".

Can there be? Not too it truly matters, just learning why people do things how they do.


You cannot change se separator. It's hard-coded into Rails. For instance, publish_554 is produced through the dom_id assistant, which internally depends on the RecordIdentifier class.

Here's the meaning.

def dom_id(record, prefix = nil) 
  if record_id = record.id
    "#{dom_class(record, prefix)}#{JOIN}#{record_id}"
    dom_class(record, prefix || NEW)

The separator, the JOIN constant, is understood to be freezed String which means you can't change it out.

module RecordIdentifier
  extend self

  JOIN = '_'.freeze
  NEW = 'new'.freeze

You will find two methods to change it out:

  1. Make your own assistant (recommended)
  2. Overwrite the present techniques/assistants with your personal implementations (not recommended)

You will find several technical limitations that explain the explanation for this choice, mainly associated with the word what behind Rails.

For example, speaking about symbols

:post_554   # valid symbol
:post-554   # invalid symbol
:"post-554" # valid symbol

Using - would most likely need a less cleaner method of Ruby.

Personally, I favor using - instead of _ and I am inclined to avoid standard Rails assistants unless of course strictly needed.