Ruby on Rails errors:

(新手期)

rails 自动化部署教程

Q1: rvm 无法使用

$ rvm use 1.9.3 --default

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.

使用:

 source ~/.rvm/scripts/rvm

或者:

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc
source ~/.bashrc

Q2: bundle install httpError

run  bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching source index from https://rubygems.org/ Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l
gem install rails #如果装rails时失败,就需要重装 #rails 项目需要使用Gemfile 和 Bundle 我们可以用 Bundler 的 Gem 源代码镜像命令。
bundle config mirror.https://rubygems.org https://gems.ruby-china.org
#这样你不用改你的 Gemfile 的 source

参考链接:ruby-china镜像站 快如闪电!

Q3: 生产秘钥 rails4 rails5 不同

ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `rails credentials:edit`

需要添加生产密钥

在rails4 中这个密钥是通过 rake secret RAILS_ENV=production 创建后放到服务器端的/home/xxx/your_web_app/shared/config/secrets.yml中的,而在rails5中改成了master.key ,使用时需要在本地的/home/xxx/your_web_app/config/deploy.rb 的:link_file手动添加 ‘config/master.key’

如:

# Default value for :linked_files is []
append :linked_files, "config/database.yml", "config/master.key"

Q4: rake aborted!

$ sudo rake secret --trace
rake aborted!
LoadError: cannot load such file -- bundler/setup

这一个可以尝试提权,用root权限运行

Beginning in Rails 4, Rails ships with a rails binstub at ./bin/rails that

should be used instead of the Bundler-generated rails binstub.

Q5: The page you were looking for doesn't exist.

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

本地测试可以,远程服务器不行.检查了一下,路由有问题,处理好远程仓库的代码(因为服务器上应该是从远程仓库上拉取代码的)

Q6: 下拉菜单无法下拉 (使用bootstrap)

下拉菜单无法下拉 (使用bootstrap)

这个功能需要js支持,所以需要包含必要的js库,在/app/assert/javascript/application.js里面添加

//= require jquery

Q7:.... ? ..... : .....

syntax error, unexpected ';' : expecting keyword_end ...cost?BCrypt::Engine::MIN_COST : BCrypt::Engine.cost

这是一个.... ? ..... : ..... 的表达式,居然没有发现,因此中间的问号与前面的判断条件需要有一个空格隔开。

Q8: 开放stmp服务的25端口

F, [2018-09-06T20:33:15.955037 #21413] FATAL -- : [bdf765fc-3c26-4d8f-87be-c5357887f443] ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
F, [2018-09-06T20:33:15.955131 #21413] FATAL -- : [bdf765fc-3c26-4d8f-87be-c5357887f443] 3: <p>
[bdf765fc-3c26-4d8f-87be-c5357887f443] 4: Welcome to the Sample App! Click on the link below to activate your account:
[bdf765fc-3c26-4d8f-87be-c5357887f443] 5: </p>
[bdf765fc-3c26-4d8f-87be-c5357887f443] 6: <%= link_to "Activate", edit_account_activation_url(@user.activation_token,
[bdf765fc-3c26-4d8f-87be-c5357887f443] 7: email: @user.email) %>
F, [2018-09-06T20:33:15.955158 #21413] FATAL -- : [bdf765fc-3c26-4d8f-87be-c5357887f443]
F, [2018-09-06T20:33:15.955180 #21413] FATAL -- : [bdf765fc-3c26-4d8f-87be-c5357887f443] app/views/user_mailer/account_activation.html.erb:6:in `_app_views_user_mailer_account_activation_html_erb__374929091__625207508'
[bdf765fc-3c26-4d8f-87be-c5357887f443] app/mailers/user_mailer.rb:11:in `account_activation'
[bdf765fc-3c26-4d8f-87be-c5357887f443] app/models/user.rb:48:in `send_activation_email'
[bdf765fc-3c26-4d8f-87be-c5357887f443] app/controllers/users_controller.rb:18:in `create'

首先是我看的教程没有配置邮件服务器的主机host

然而配置完成后又出现内网连接超时的问题,

I, [2018-10-07T23:58:53.103195 #26716]  INFO -- : [084c0592-31a4-492c-8686-9cac1b6d2ead] Completed 500 Internal Server Error in 30173ms (ActiveRecord: 7.9ms)
F, [2018-10-07T23:58:53.104096 #26716] FATAL -- : [084c0592-31a4-492c-8686-9cac1b6d2ead]
F, [2018-10-07T23:58:53.104154 #26716] FATAL -- : [084c0592-31a4-492c-8686-9cac1b6d2ead] Net::OpenTimeout (execution expired):
F, [2018-10-07T23:58:53.104187 #26716] FATAL -- : [084c0592-31a4-492c-8686-9cac1b6d2ead]
F, [2018-10-07T23:58:53.104220 #26716] FATAL -- : [084c0592-31a4-492c-8686-9cac1b6d2ead] app/models/user.rb:48:in `send_activation_email'
[084c0592-31a4-492c-8686-9cac1b6d2ead] app/controllers/users_controller.rb:18:in `create'

结果发现是:腾讯云封禁了stmp服务的25端口,so。。工单申请解禁之后就可以正确发送激活的邮箱了。

Q7: 服务器端运维

如何在服务器端增删model对象的属性

在current文件夹下运行 rails console prodution才能正常访问生产环境下的数据信息

因为模型的文件model/在当前项目文件夹是没有文件的,即便rails可以运行,他也找不到model对象就会出现:

irb(main):001:0> User.first
Traceback (most recent call last):
1: from (irb):1
NameError (uninitialized constant User)

另外需要注意的是,如果本地用的mysql和远程使用的mysql密码不一样的话,,database.yml的配置也要不一样

服务器端的用户模型已经有reset_at 属性,使用的迁移肯定有问题

要注意旧的时间戳的迁移,在已经执行过迁移之后重新使用db:migrate是没有效果的,除非db:rollback之后才有效果,想要对数据库做新的增删,需要建立新的迁移文档d

本地测试非常非常重要啊小老弟

所以别在瞎提交本地分支到服务器进行部署,弄错了,麻烦得一匹

Q9: 科学计算环境

对了不要别的什么科学计算环境下运行rails虚拟环境

其实就是anaconda,会触发LoadError

Q10: 测试固件

测试失败 之 固件错误  显示nil

解决方法: 在test/fixtures/xxx.yml 中添加所需要的测试固件

'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.

view的变量是nil ,所以无法渲染界面

解决: 检查对应的controller 中是否定义了这个变量

Q11: Gemfile与本地的包版本不同

/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:313:in `check_for_activated_spec!': You have already activated i18n 1.1.1, but your Gemfile requires i18n 1.1.0. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

这是当前激活的包和Gemfile中要求的不一样,可以更改Gemfile,也可以运行bundle update重新配置包

ruby-on-rails-BUG的更多相关文章

  1. 10 steps to get Ruby on Rails running on Windows with IIS FastCGI- 摘自网络

    Since the original tech preview release of FastCGI last year, we've been seeing a lot of requests fo ...

  2. Ruby on Rails创始人DHH谈如何进行混合移动APP开发

    混合型APP兼具原生型APP软件良好用户交互体验的优势和网页型APP软件跨平台开发的优势,并且其开发成本和网页型APP软件接近,其开发效率也远高于原生型APP软件.混合型APP已经被众多企业所认可.最 ...

  3. ubuntu 14.04中安装 ruby on rails 环境

    环境:在win7 上Vmware虚拟机环境中安装的ubuntu 14.04 1. bundle install 时,报json错误可以看出是在安装nokogiri时遇到了问题,此时执行 sudo ap ...

  4. [Ting's笔记Day4]将Ruby on Rails项目部署到Heroku

    今天想笔记的是把自己写的Ruby on Rails项目部署(Deploy)到Heroku! Heroku是Salesforce公司旗下的云端服务商,支持多种程序语言像是Ruby,PHP,Python等 ...

  5. Ruby on Rails Tutorial 第2版 学习笔记

    Ruby on Rails Tutorial 第2版 在线阅读:http://railstutorial-china.org/ 英文版:http://ruby.railstutorial.org/ru ...

  6. ubuntu 14.04中安装 ruby on rails 环境(填坑版) 呕血推荐

    环境:在win7 上Vmware虚拟机环境中安装的ubuntu 14.04 开发相关: ruby 2.2.0 rails 4.2.0 sublime text 3 本文说明:所有的命令均在$ 之后,若 ...

  7. Linux超快速安装Ruby on Rails

    Linux超快速安装Ruby on Rails 时间 2014-11-25 11:45:11 Flincllck Talk 原文  http://www.flincllck.com/quick-ins ...

  8. 管理不同版本ruby和rails的利器——rvm

    近年来,ruby on rails逐渐火了起来,我想各位码农早就耳闻,特别是那些做B/S项目的童鞋,早就想跃跃一试了. 笔者也是初次接触ruby on rails ,我想,对于初学者来说,最好的学习方 ...

  9. ruby on rails on windows

    这次想系统学会rails,最终目标是将redmine改造成顺手的工具,主要的手段就是开发redmine插件.虽然网上都推荐使用类Unix系统,可手头只有win7系统,就安装了. 难免会遇到这样那样的问 ...

  10. win8平台下Ruby on Rails的第一个web应用

    最近在做一个网站web前端的前期开发,老板要求用Ruby on Rails搭建部署开发环境,上网搜之,发现整个搭建流程比较坑爹,于是用了一款集成软件Bitnami Ruby Stack一键安装到我的w ...

随机推荐

  1. VsCode中编写python环境配置

    1. VsCode中编写python环境配置 1.1. 前言 有过开发经验都知道idea一系列的软件虽然功能比较多,但比较容易卡,电脑不好还真容易上火,这里我想要入门python,还是选了款vscod ...

  2. uni-app学习(二)

    1. uni-app学习(二) 1.1. 好用css记录 一定透明度的背景色background: rgba(255,255,255,.6); 1.2. 好用的代码段 store(用户登录) expo ...

  3. JavaScript 之 Date对象

    Date对象 Date 是一个构造函数,首先要通过 new Date() 来创建实例对象,提供实例成员.  创建 Date 实例用来处理日期和时间.Date 对象基于 1970年1月1日(世界标准时间 ...

  4. ObjC: 源文件的组织

    转自:http://marshal.easymorse.com/tech/objc-%e6%ba%90%e6%96%87%e4%bb%b6%e7%9a%84%e7%bb%84%e7%bb%87 最简单 ...

  5. 微服务spring-cloud 学习第一天

    了解微服务     微服务架构风格是一种将单一应用程序开发为一组小型服务的方法,每个服务运行在自己的进程中,服务间通信采用轻量级通信机制(通常使用HTTP).这些服务围绕业务能力构建并且可通过自动部署 ...

  6. markdown 格式测试

    Q1: before 与 afer 的而区别在哪? Q2: 如何预防"爆仓"? Q3: 在购买量 much > 库存量 num时, 把much自动改为num? -- 在t2的 ...

  7. 浅谈布隆过滤器Bloom Filter

    先从一道面试题开始: 给A,B两个文件,各存放50亿条URL,每条URL占用64字节,内存限制是4G,让你找出A,B文件共同的URL. 这个问题的本质在于判断一个元素是否在一个集合中.哈希表以O(1) ...

  8. centos 服务器 nginx 负载均衡服务安装

    yum -y install gcc gcc-c++ autoconf automake libtool make cmake yum -y install zlib zlib-devel opens ...

  9. 【异常】[ERROR] The cloud assistant is not installed on the ECS, or the cloud assistant is unavailable. cloudassistant is uninstall

    一.异常信息 [INFO] Deployment File is Uploading... [INFO] IDE Version:IntelliJ IDEA [INFO] Alibaba Cloud ...

  10. shell中read用法

    1. Read的一些选项 Read可以带有-a, -d, -e, -n, -p, -r, -t, 和 -s八个选项. -a :将内容读入到数值中 1 2 3 echo -n "Input m ...