开发者

model name to controller name

Ho开发者_运维问答w can I get the controller name out of the object if I don't know what the object is?

I am trying to do:

object.class.tableize

but Rails says:

undefined method `tableize' for #<Class:0xb6f8ee20>

I tried adding demodulize with same result.

thanks


object.class.to_s.tableize


For semantic reasons, you might want to do:

object.class.name #=> 'FooBar'

You can also use tableize with this sequence, like so:

object.class.name.tableize #=> 'foo_bars'

I prefer it that way due to readability.

As well, note that tableize also does pluralization. If unwanted use underscore.

Hope it helps anyone, even if it's an old thread :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜