簡體   English   中英

正確的Rails是否有下划線'下划線'?

[英]Is the proper Rails inflection of underscore 'underscoreize'?

看來,通過ActiveSupport將Rails / AR和Inflector方法添加到String ,我希望默認情況下,

Nested::ClassDerived::FromAR.name.tableize == Nested::ClassDerived::FromAR.table_name

但實際上tableize調用underscore ,而underscore實際上並不強調::嵌套類分隔符,而是用/替換它來創建路徑名。 也許這個方法應該叫做pathify

無論如何,我需要實際的下划線。 所以我正在考慮定義一個新的String inflector方法:

def new_inflector
  underscore.gsub('/', '_')
end

這實際上會強調嵌套的類名字符串。

所以,我的問題是,為了正確和常規地命名我的新變形器方法,沒有配置,“ underscore ”的適當變化是什么。 難道是“ underscoreize ”(由“建立的規則如下tableize或‘’) underscorize ”? 或者可能是underscoreify

有任何見解贊賞。

您是否嘗試使用下划線作為分隔符進行參數化?

parameterize('_')

這適用於Ruby 2.5.0Rails 5.1.6

"Admin::Role".parameterize.underscore
#=> "admin_role"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM