0

我知道 session_store 已从 Rails 4 中删除。

所以我尝试安装它,但有一些错误:

宝石文件

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

gem 'activerecord-session_store', github: 'rails/activerecord-session_store', plataform: :mri

安慰

捆绑安装
C:\Sites\rails-estudo-blog>bundle install
Using rake (10.1.0)
Using i18n (0.6.5)
Using minitest (4.7.5)
Using multi_json (1.8.0)
Using atomic (1.1.14)
Using thread_safe (0.1.3)
Using tzinfo (0.3.37)
Using activesupport (4.0.0)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.0)
Using mime-types (1.25)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.0)
Using activemodel (4.0.0)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.0)
Using activerecord (4.0.0)
Using coffee-script-source (1.6.3)
Using execjs (2.0.1)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.0)
Using coffee-rails (4.0.0)
Using hike (1.2.3)
Using jbuilder (1.5.1)
Using jquery-rails (3.0.4)
Using json (1.8.0)
Using bundler (1.3.5)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.0.0)
Using rdoc (3.12.2)
Using sass (3.2.10)
Using sass-rails (4.0.0)
Using sdoc (0.3.20)
Using sqlite3 (1.3.8)
Using turbolinks (1.3.0)
Using uglifier (2.2.1)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

C:\Sites\rails-estudo-blog>
尝试安装 gem
C:\Sites\rails-estudo-blog>rails generate active_record:session_migration
Could not find generator active_record:session_migration.    
尝试创建会话存储迁移
C:\Sites\rails-estudo-blog>rails generate active_record:session_migration
Could not find generator active_record:session_migration.

C:\Sites\rails-estudo-blog>

资讯

  • 导轨 4.0
  • 红宝石 2.0
  • Windows 7 x64 专业版

怎么了?我遵循存储库的所有步骤:https ://github.com/rails/activerecord-session_store


作品!

我重写了文件,并且可以工作(我不知道问题所在),但是我还有另一个问题(我使用代理)。

$ bundle install
Fetching git://github.com/rails/activerecord-session_store.git
fatal: unable to connect to github.com:
github.com[0: 192.30.252.129]: errno=No error

Git error: command `git clone
"git://github.com/rails/activerecord-session_store.git"
"c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/cache/bundler/git/activerecord-session_store-cf0cfe22b7614cc4fcd416e139ff2bd62ebd6f1d"
--bare --no-hardlinks` in directory c:/Sites/rails-estudo-blog has failed.

解决了

我可以解决问题将网址更改为:

gem 'activerecord-session_store', git: 'https://github.com/rails/activerecord-session_store'

因此,我将github更改为git并放入我想要的整个 url。

谢谢!


4

1 回答 1

2

更新新答案:

在你提供了整个 Gemfile 之后,我复制它并直接尝试。我看到了和你一样的问题。所以,我重新输入了该行。有效。我不能确切地说出这行内有什么问题,但这有效:

gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

复制并尝试一下。如果仍然失败,请将其删除并重新键入。原始行只是在没有任何消息或原因的情况下被忽略,并且捆绑成功但错过了这个宝石。新键入的行有效。去搞清楚。

我省略了“平台::mri”,更正为“平台::mri”,因为它是无关的。

请务必遵循我原始答案中概述的步骤。他们仍然适用。

请告诉我..

以新答案结束更新。旧答案如下:

我为你试过这个,更新 Gemfile 并运行 bundle install。结果添加了所需的 gem,您可以从 git 中看到初始获取(这是使用 Rubymine 执行的,因此是复杂的命令行。):

D:\BitNami\rubystack-1.9.3-12\ruby\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) D:/BitNami/rubystack-1.9.3-12/projects/utilities/bin/bundle install
Fetching git://github.com/rails/activerecord-session_store.git
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
...
Using activerecord-session_store (0.0.1) from git://github.com/rails/activerecord-session_store.git (at master) 
...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
Process finished with exit code 0

检查状态,我发现:

D:\BitNami\rubystack-1.9.3-12\projects\utilities\app\helpers>bundle show activerecord-session_store
D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/bundler/gems/activerecord-session_store-022d45b4ae9b

运行生成创建了迁移:

D:\BitNami\rubystack-1.9.3-12\projects\utilities>rails generate active_record:session_migration
      create  db/migrate/20131002090526_add_sessions_table.rb

迁移如下:

class AddSessionsTable < ActiveRecord::Migration
  def change
    create_table :sessions do |t|
      t.string :session_id, :null => false
      t.text :data
      t.timestamps
    end

    add_index :sessions, :session_id, :unique => true
    add_index :sessions, :updated_at
  end
end

有趣的是,gem list 并没有显示我期望的 gem,即使 bundle 和 generate 有效:

D:\BitNami\rubystack-1.9.3-12\projects\utilities>gem list activerecord-session_store
*** LOCAL GEMS ***

D:\BitNami\rubystack-1.9.3-12\projects\utilities>gem list activerecord-session_store -r
*** REMOTE GEMS ***
activerecord-session_store (0.0.1)

但是, gem install 修复了:

D:\BitNami\rubystack-1.9.3-12\projects\utilities>gem install activerecord-session_store
Fetching: activerecord-session_store-0.0.1.gem (100%)
Successfully installed activerecord-session_store-0.0.1
1 gem installed
D:\BitNami\rubystack-1.9.3-12\projects\utilities>gem list activerecord-session_store
*** LOCAL GEMS ***
activerecord-session_store (0.0.1)

建议:

  1. 运行 gem install 以确保您已安装它。
  2. 运行 gem 列表进行仔细检查。
  3. 运行捆绑更新,而不是捆绑安装,从头开始构建捆绑。
  4. 检查清单以确保按预期包含 gem。
  5. 再次运行 bundle show 以再次检查...
  6. 运行 rails generate 以生成迁移。

如果迁移无法再次运行,请在 gem 存储中检查生成器的 gem 存储:

.../gem/activerecord-session_store-0.0.1/lib/active_record/session_store.rb
于 2013-10-02T09:31:59.967 回答