我创建了两个相关的Rails应用程序,并且我注意到很多非DRY工作。Rails应用程序设置
例如,@title
领域中的各种控制器方法被设置做同样的事情,除了应用程序标题,如:
# SiteController (application 'Abc')
def SiteController < ApplicationController
def index
@title = 'Abc'
end
def about
@title = 'about Abc'
end
def news
@title = 'Abc news'
end
def contact
@title = 'contact Abc'
end
end
和:
# SiteController (application 'Xyz')
def SiteController < ApplicationController
def index
@title = 'Xyz'
end
def about
@title = 'about Xyz'
end
def news
@title = 'Xyz news'
end
def contact
@title = 'contact Xyz'
end
end
我”什么米寻找做的是有像
# SiteController
def SiteController < ApplicationController
def index
@title = "#{ApplicationTitle}'
end
def about
@title = "about #{ApplicationTitle}"
end
def news
@title = "#{ApplicationTitle} news"
end
def contact
@title = "contact #{ApplicationTitle}"
end
end
我想图的东西是:应该在哪里定义不变的应用程序设置。它在config/* rb文件中吗?它是否在.yaml文件之一中?
在此先感谢
谢谢。我打算它是一个常数,但不知道environment.rb(或其他地方,对于这个问题)。 – dcw 2009-05-19 06:35:11