开发者

Default Properties on Application_Controller for default layout

开发者 https://www.devze.com 2023-03-25 17:09 出处:网络
Can I create a default property on the base Application_Controller that can be accessed in my application.html.haml view?

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

精彩评论

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