我开始在铁轨上学习红宝石。我有的问题是,我不知道为什么我到那里,而我想创建模型 这是我试过的命令 rails生成模型书
并在我的ubuntu 16终端中出现此错误
/home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/app_loader.rb:40: warning: Insecure world writable dir /opt in PATH, mode 040777
/home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/application/configuration.rb:148:in `rescue in database_configuration': YAML syntax error occurred while parsing /home/android/ruby Tutorial/library/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): found a tab character that violate intendation while scanning a plain scalar at line 17 column 10 (RuntimeError)
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/application/configuration.rb:131:in `database_configuration'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-5.0.1/lib/active_record/railtie.rb:122:in `block (2 levels) in <class:Railtie>'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/lazy_load_hooks.rb:43:in `instance_eval'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/lazy_load_hooks.rb:43:in `execute_hook'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/lazy_load_hooks.rb:49:in `each'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-5.0.1/lib/active_record/base.rb:324:in `<module:ActiveRecord>'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-5.0.1/lib/active_record/base.rb:24:in `<top (required)>'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:345:in `active_record_configured?'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:263:in `disconnect_database'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:97:in `preload'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:143:in `serve'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:131:in `block in run'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:125:in `loop'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application.rb:125:in `run'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/spring-2.0.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/android/.rbenv/versions/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
我也试过这个
rails script/generate model Book
我收到此错误:
/home/android/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.1/lib/rails/app_loader.rb:40: warning: Insecure world writable dir /opt in PATH, mode 040777
rails aborted!
Don't know how to build task 'script/generate' (see --tasks)
/home/android/ruby Tutorial/library/bin/rails:9:in `require'
/home/android/ruby Tutorial/library/bin/rails:9:in `<top (required)>'
/home/android/ruby Tutorial/library/bin/spring:14:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
//修改
我检查了我的数据库但是也检查了yamlint网站在第17行也有错误但是没有错误
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: mysql
pool: 5
timeout: 5000
development:
adapter: mysql
database: library_development
username: root
password: root1234
host: localhost
test:
adapter: mysql
database: library_test
username: root
password: root1234
host: localhost
production:
adapter: mysql
database: library_production
username: root
password: root1234
host: localhost
答案 0 :(得分:1)
主要问题是您的database.yml
文件。您在文件中有tab space
,而YAML
文件不允许这样,因为不同的编辑器和工具对它们的处理方式不同。缩进是正确解释YAML最关键的部分。所以在第17行解决了这个问题。对于永久性解决方案,请根据该设置保留文本编辑器的设置。我使用Sublime
,在每个页面上我都可以选择Convert Indentation to Spaces
,在其配置中我可以设置"translate_tabs_to_spaces": true
。
关于您尝试的第二个命令:
rails script/generate model Book
它属于Rails 2
版本。而是仅使用新命令:
rails generate model Book
答案 1 :(得分:0)
您在Rails 5上使用Rails 2的命令。
要在Rails 5中生成模型,您应该使用:
rails generate model Book
答案 2 :(得分:0)
config/database.yml
是否有效
答案 3 :(得分:0)
检入您的应用程序数据库文件。它位于/config/database.yml中。如果您没有该文件,则可以从同一目录中的dtabase.yaml.exemple进行复制。
答案 4 :(得分:0)
这是你的间距,你的开发,测试和生产部分看起来你有3个空格而不是2个。
2个空格:
default: &default
adapter: mysql
pool: 5
timeout: 5000
3个空格:
development:
adapter: mysql