首页 > 解决方案 > ruby rails:索引中的 ArgumentError:键必须是 32 个字符

问题描述

我只是Rails的新手。
我正在关注https://guides.rubyonrails.org/getting_started.html上的教程,我遇到了这个问题:我创建了一个运行的控制器 rails generate controller Welcome index,然后添加get 'welcome/index' root 'welcome#index'config/routes.rb. 打开localhost:3000(ruby 服务器的默认值)给我这个错误页面

我在 StackOverflow 和 GitHub 上做了一些研究,发现问题可以通过在 gemfile 中链接 github 上的 rails 5-0-stable 版本来解决,但是 bundle install 找不到 git 文件。我也尝试更改 config/routes.rb,但这似乎不是问题。我读了一些关于更改源文件中调用的答案,但我不明白他们在谈论哪个文件(https://github.com/rails/rails/issues/25448

红宝石和轨道版本:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
Rails 4.2.6

PS:我认为这与此无关,但是我在启动服务器时遇到了一些问题,因为 bundle install 给出了error: couldn't build native extensions,我解决了通过 apt 安装 ruby​​-dev 和通过gem install.

编辑:

从终端运行的命令:

$ rails new blog
$ cd blog
$ rails server

编辑的文件:

#config/routes.rb
Rails.application.routes.draw do
  get 'welcome/index'
  root 'welcome#index'
  get 'layout/application'
end

谢谢你的帮助!

尝试链接 github ruby​​ 5.2 后:

$ bundle install
Fetching https://github.com/rails/rails.git
sh: 1: git: not found
Retrying `git clone 'https://github.com/rails/rails.git' "~/.bundle/cache/git/rails-fcf0202857b07db1a0f6220dae5ca99319ca0f32" --bare --no-hardlinks --quiet` due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'https://github.com/rails/rails.git' "~/.bundle/cache/git/rails-fcf0202857b07db1a0f6220dae5ca99319ca0f32" --bare --no-hardlinks --quiet` in directory ~/script/ruby/blog has failed.sh: 1: git: not found
Git error: command `git clone 'https://github.com/rails/rails.git'
"~/.bundle/cache/git/rails-fcf0202857b07db1a0f6220dae5ca99319ca0f32" --bare
--no-hardlinks --quiet` in directory ~/script/ruby/blog has failed.

标签: ruby-on-railsrubyruby-on-rails-4

解决方案


好像您刚刚开始了一个新的 Rails 应用程序?如果是这样,您应该直接使用 Rails 5.2,它在撰写本文时似乎是最新的稳定版本。

在我生成的 Gemfile 的顶部,rails s我有以下内容

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

# Rails
gem 'rails', github: "rails/rails", branch: "5-2-stable"

尝试使用此更改您的 Gemfile 并重新运行bundle

此外,为了管理您的 ruby​​ 版本,我强烈建议您切换到rbenv而不是让您的系统管理 Ruby 版本


推荐阅读