Search code examples
ruby-on-railsrubymodelnaming-conventionsacronym

Rails model naming partial acronym word


So. For some reason I'm struggling with Rails naming today. I feel like the best naming for a model I'm creating is DNSRecord for the camel case class model name and dns_record for snake case referencing -- Rails wants to name it DnsRecord.

I've seen a solution if the entire word is capitalized for example: API

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'API' 
end

but doesn't seem to work well as:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'DNSRecord' 
end

it still wants to refer to DnsRecord. I know this is a small thing but DNSRecord feels better to me.


Solution

  • I believe you will want inflect.acronym 'DNS' rather than 'DNSRecord'. You will likely also have to restart your server after updating the inflections file.