ruby-on-rails-BUG

Ruby on Rails errors:

(新手期)javascript

rails 自動化部署教程html

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.

使用:java

source ~/.rvm/scripts/rvm

或者:mysql

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

rails 項目須要使用Gemfile 和 Bundle 咱們能夠用 Bundler 的 Gem 源代碼鏡像命令。

bundle config mirror.https://rubygems.org https://gems.ruby-china.orgjquery

這樣你不用改你的 Gemfile 的 source

```web

參考連接:ruby-china鏡像站 快如閃電!sql

Q3: 生產祕鑰 rails4 rails5 不一樣

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

須要添加生產密鑰shell

在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’數據庫

如:bootstrap

# 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從新配置包

相關文章
相關標籤/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。