美文网首页
Ruby on Rails初体验

Ruby on Rails初体验

作者: 千伞万伞 | 来源:发表于2019-12-30 19:26 被阅读0次

记录下自己的初体验过程中的问题,同时很疑惑,国内怎么就一直没有Ruby on Rails的动静呢😖😖

在执行 gem install rails 的后,提示我需要的ruby版本为2.4.x(具体忘记了)以上,但是我的版本还是老版本;

于是更新ruby版本,通过执行rvm install 2.4.x,但是报错,只记得说rvm找不到该版本,导致更新失败;于是尝试更高版本,还是一样报错,结果如下:

屏幕快照 2019-12-30 18.04.52.png
于是列出已知的ruby版本 rvm list known,执行结果如下:
屏幕快照 2019-12-30 18.32.26.png

最后自己莫名其妙选择安装2.6.5版本,最终成功安装
以上有点奇怪之处,列出已知版本有2.6.3,但是安装失败,已知版本没有2.6.5,但是安装成功了,或许我理解有误,导致我还是很困惑,望明白之人告知,抱拳了

好了,ruby版本对应好了,那么就开始安装rails了, gem install rails,等待,漫长的等待。
最后提示

Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, zeitwerk, activesupport, rack, rack-test, mini_portile2, nokogiri, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 45 seconds
40 gems installed

OK了的,那就开始rails之路吧,手动分割✌️

创建博客应用rails new blog,提示我没有安装Node.js,如下:

sh: node: command not found
sh: nodejs: command not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/

进入提示网址,选择对应版本,会下载一个Node.js的安装器,按照提示即可,但是此时我并没有等待下载安装,而是执行以下步骤了

查看rails官网,You actually have a functional Rails application already. To see it, you need to start a web server on your development machine. You can do this by running the following in the blog directory(应用程序有了,我们启动一个web服务器):
rails server
但是报错,如下

/Users/macbook/.rvm/gems/ruby-2.6.5/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /Users/macbook/blog/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/macbook/blog/config/webpacker.yml (RuntimeError)

网上搜一下,解决的话需要执行:bundle exec rails webpacker:install,结果如下

Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/

使用brew install yarn安装即可,小插曲:输出日志有很多有关node的问题,不知道是不是因为我那时候还没有装Node.js,我是又安装了Node.js,然后再执行bundle exec rails webpacker:install就OK了,这步也费点时间

当看到很多successful后,尤其是以下这句,就代表OK了。

Webpacker successfully installed 🎉 🍰

让我们看看我们生什么了吧,啊,生成

进入目录 cd blog
打开该目录 open .

屏幕快照 2019-12-30 19.36.54.png

再执行rails server,结果如下

屏幕快照 2019-12-30 19.24.19.png
于是打开浏览器,输入 http://127.0.0.1:3000,嗒嗒~
屏幕快照 2019-12-30 19.26.09.png

相关文章

网友评论

      本文标题:Ruby on Rails初体验

      本文链接:https://www.haomeiwen.com/subject/fibmoctx.html