Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 使用Rails3Gem宣言_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 使用Rails3Gem宣言

Ruby on rails 3 使用Rails3Gem宣言,ruby-on-rails-3,Ruby On Rails 3,我试图使用名为Manifesto的gem来使用HTML5清单函数。我被使用说明卡住了。我不知道这些设置应该放在哪里 有什么想法吗?也许是更好的宝石 感谢所有的帮助 您可以将设置放在config/initializers/下的文件中。使用信息性名称(如manifesto.rb)。但是,您不需要具有基本用法的配置 在Gemfile文件中,添加: gem 'manifesto' 然后通过bundle安装: bundle install 创建文件app/controllers/manifest\u

我试图使用名为Manifesto的gem来使用HTML5清单函数。我被使用说明卡住了。我不知道这些设置应该放在哪里

有什么想法吗?也许是更好的宝石


感谢所有的帮助

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

Gemfile
文件中,添加:

gem 'manifesto'
然后通过bundle安装:

bundle install
创建文件
app/controllers/manifest\u controller.rb

class ManifestController < ApplicationController
  def show
    headers['Content-Type'] = 'text/cache-manifest'
    render :text => Manifesto.cache, :layout => false
  end
end
重新启动应用程序,并在上查看结果

您可以将该选项直接传递给
Manifesto.cache
,如:

# change
render :text => Manifesto.cache, :layout => false
# to
render :text => Manifesto.cache(:directory => './mobile', :compute_hash => false), :layout => false
# change
render :text => Manifesto.cache, :layout => false
# to
render :text => Manifesto.cache(MANIFESTO_CONFIG), :layout => false
或者使用YAML文件和初始值设定项

config/manifesto.yaml
文件:

# directory is relative to Rails root
directory: './mobile'
compute_hash: false 
# 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}
config/initializers/manifesto.rb
文件:

# directory is relative to Rails root
directory: './mobile'
compute_hash: false 
# 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(:directory => './mobile', :compute_hash => false), :layout => false
# change
render :text => Manifesto.cache, :layout => false
# to
render :text => Manifesto.cache(MANIFESTO_CONFIG), :layout => false

看起来不错,谢谢!我在manifesto.rb文件中到底放了什么?@Jonathan Clark-你不需要配置文件(所以你不需要manifesto.rb文件)。但是我在哪里选择要使用的文件夹呢?