Rails model naming partial acronym word

Michael K Madison

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.

Derek Prior

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.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事