2
是否有任何簡單的方法從Model類獲取控制器類名? 例子:Rails 4:從模型類獲取控制器類
Invoice => InvoicesController
嘗試tabalize但它返回 「發票」
Invoice.to_s.tabalize => "invoices"
是否有任何簡單的方法從Model類獲取控制器類名? 例子:Rails 4:從模型類獲取控制器類
Invoice => InvoicesController
嘗試tabalize但它返回 「發票」
Invoice.to_s.tabalize => "invoices"
s = Invoice
s.name.pluralize + 'Controller'
=> "InvoicesController"
爲了讓控制器類本身...
"InvoicesController".constantize
=> InvoicesController