是否可以覆盖`rails new first_app`期间生成的冲突?

时间:2012-10-31 15:33:20

标签: ruby-on-rails

$ cd rails_projects $ rails new first_app

我在下面的输出底部遇到了这个冲突:conflict config/initializers/secret_token.rb

       exist  
   identical  README.rdoc
   identical  Rakefile
   identical  config.ru
   identical  .gitignore
   identical  Gemfile
       exist  app
   identical  app/assets/images/rails.png
   identical  app/assets/javascripts/application.js
   identical  app/assets/stylesheets/application.css
   identical  app/controllers/application_controller.rb
   identical  app/helpers/application_helper.rb
       exist  app/mailers
       exist  app/models
   identical  app/views/layouts/application.html.erb
   identical  app/mailers/.gitkeep
   identical  app/models/.gitkeep
       exist  config
   identical  config/routes.rb
   identical  config/application.rb
   identical  config/environment.rb
       exist  config/environments
   identical  config/environments/development.rb
   identical  config/environments/production.rb
   identical  config/environments/test.rb
       exist  config/initializers
   identical  config/initializers/backtrace_silencers.rb
   identical  config/initializers/inflections.rb
   identical  config/initializers/mime_types.rb
    conflict  config/initializers/secret_token.rb
Overwrite /Users/XXXXXX/rails_projects/first_app/config/initializers/secret_token.rb? (enter "h" for help) [Ynaqdh] 

config/initializers/secret_token.rb做什么?我之前运行了这个并覆盖了代码并安装了捆绑包,但想知道是否有意外的后果。谢谢!

1 个答案:

答案 0 :(得分:0)

Ruby中基于Cookie的会话使用秘密令牌来保证使用秘密字符串创建cookie,并且无法轻松地重新创建。

更改密钥令牌不会影响任何内容,除非您在用户登录时更改生产,这将导致他们被注销,因为他们将无法识别出具有与您的令牌匹配的有效cookie。

如果您想生成新的秘密令牌,只需运行:

rake secret

(或者,如果你想的话,你可以自己简单地生成一个长串)

虽然让这个文件远离任何开源存储库是很重要的,因为通过访问它,人们可以在你的Rails网站上劫持会话

有关它的更多信息Reminder: secret_token.rb is named so for a reason.

HTH

<强>更新

另外,如果您想阅读更多内容,可以找到一篇关于它的优秀文档文章here