无法在 OSX 上设置(我自己的)预建 Rails 应用程序

Failing to set up (my own) prebuilt Rails app on OSX

完成 Rails Tutorial 后,我想将它扩展到个人应用程序中,所以我创建了另一个目录和 moved/copied 从 tutorialFolderappFolder.

但是,当我再次尝试设置 gem 时遇到了一些问题。

bundle install returns:

An error occurred while installing pg (0.17.1), and Bundler cannot continue. 
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

所以我尝试 gem install pg -v '0.17.1(或 bundle update)并得到:

You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

搜索 Whosebug 我发现 Installing gem or updating RubyGems fails with permissions error

这说明 /Library/Ruby/Gems/2.0.0

That is the version of Ruby installed by Apple, for their own use. While it's OK to make minor modifications to that if you know what you're doing, because you are not sure about the permissions problem, I'd say it's not a good idea to continue along that track.

为了避免上述情况,我尝试 brew install ruby 成功但卡在 bundle install

我无法回溯到哪里,但我也尝试删除 Gemfile.lock 但那没有做任何事情。

附加信息:ruby -v >>> ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

rails -v >>> bin/spring:10:in 'read': No such file or directory - /Gemfile.lock (Errno::ENOENT)

bundle install --path vendor/bundle >>> An error occurred while installing pg (0.17.1), and Bundler cannot continue.

谢谢,

编辑* 我尝试从头开始 rails new app 但是得到了这个:

Bundle complete! 12 Gemfile dependencies, 54 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
run  bundle exec spring binstub --all
/Library/Ruby/Gems/2.0.0/gems/bundler-         1.10.5/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find  i18n-0.7.0 in any of the sources (Bundler::GemNotFound)
from /Library/Ruby/Gems/2.0.0/gems/bundler-  1.10.5/lib/bundler/spec_set.rb:85:in `map!'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/spec_set.rb:85:in `materialize'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/definition.rb:140:in `specs'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/definition.rb:185:in `specs_for'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/definition.rb:174:in `requested_specs'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/environment.rb:18:in `requested_specs'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/runtime.rb:13:in `setup'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler.rb:127:in `setup'
from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.5/lib/bundler/setup.rb:18:in `<top (required)>'
from /usr/local/Cellar/ruby/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/Cellar/ruby/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

上面的块已用 rvm gemset empty 修复,然后我能够设置 VANILLA rails 应用程序,仍然无法与教程结束同步

听起来您试图通过复制所有文件来创建 rails 应用程序的副本。我愿意

rails new appFolder

要使用 rails 设置创建一个新目录,然后只需复制 tutorialFolder 中的所有文件即可替换 appFolder 中的文件。

从 rails 教程的 this section 我添加了以下代码:

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

解释

Note also the addition of the rails_12factor gem, which is used by Heroku to serve static assets such as images and stylesheets. The resulting Gemfile appears as in Listing 1.14.

To prepare the system for deployment to production, we run bundle install with a special flag to prevent the local installation of any production gems (which in this case consists of pg and rails_12factor):

bundle install --without production

一切正常。