ruby-on-rails - 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.
解决方案
好像您刚刚开始了一个新的 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 版本
推荐阅读
- google-cloud-platform - gsutil 说它找不到 python
- c++ - Visual Studio 2019 MFC 应用程序:如何从文本文件中读取并在不同字段/编辑控件中显示字符串?
- swiftui - 动态设置 SwiftUI NavigationBarItems?
- json - 仅打印数组属性中的对象的一个属性以及与 jq 中的数组属性同级的属性
- android - 为什么我的图标形状不像 Android 上的其他图标?
- javascript - Javascript / React Native - 如何在两个不同的对象数组之间进行交叉检查?
- mysql - phpmyadmin 这是索引大小吗?
- python - 我们如何将列表作为函数中的参数?
- ruby - 初始化方法中的'self.class.class_method_name'有什么作用?
- java - 创建没有重复的随机整数数组