有没有简单的方法从Model类中获取Controller类名? 例如:
Invoice => InvoicesController
尝试tabalize,但它会返回"发票"
Invoice.to_s.tabalize => "invoices"
答案 0 :(得分:4)
s = Invoice
s.name.pluralize + 'Controller'
=> "InvoicesController"
获取控制器类本身......
"InvoicesController".constantize
=> InvoicesController