开发者

Default Properties on Application_Controller for default layout

Can I create a default property on the base Application_Controller that can be accessed in my application.html.haml view?

What I'm trying to do is show a random quote on every page of the site. I have the quotes working, no problems, but I have to set

@quote = Quote.f开发者_如何学JAVAirst(:order => "RANDOM()")

on every method in every controller. There must be a DRYer way than that?

Cheers

Ben


You're on the right way.

Wrap your query in a before_filter inside your ApplicationController and add in your application layout the necessary stuff to display your result.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜