2010-11-23 64 views

回答

1

你可以把你的设置放在config/initializers/下的文件中。使用信息名称(如manifesto.rb)。但是,您不需要具有基本用法的配置。

在你Gemfile文件,添加:

gem 'manifesto' 

然后通过捆绑安装:

bundle install 

config/routes.rb添加创建文件app/controllers/manifest_controller.rb

class ManifestController < ApplicationController 
    def show 
    headers['Content-Type'] = 'text/cache-manifest' 
    render :text => Manifesto.cache, :layout => false 
    end 
end 

match '/manifest' => 'manifest#show' 

重新启动应用程序并查看结果在http://localhost:3000/manifest

您可以直接通过选项Manifesto.cache,如:

# change 
render :text => Manifesto.cache, :layout => false 
# to 
render :text => Manifesto.cache(:directory => './mobile', :compute_hash => false), :layout => false 

或者使用一个YAML文件和初始化。

config/manifesto.yaml文件:

# directory is relative to Rails root 
directory: './mobile' 
compute_hash: false 

config/initializers/manifesto.rb文件:

# Load the config file and convert keys from strings in symbols (the manifesto gem need symbolized options). 
MANIFESTO_CONFIG = YAML.load_file(Rails.root.join('config', 'manifesto.yml').to_s).inject({}){|config,(k,v)| config[k.to_sym] = v; config} 

而调入的配置传递给Manifesto.cache,如:

# change 
render :text => Manifesto.cache, :layout => false 
# to 
render :text => Manifesto.cache(MANIFESTO_CONFIG), :layout => false 
+0

看起来不错,谢谢!我把什么放在manifesto.rb文件中? – 2010-11-23 19:26:56