iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 19
4

前情提要

昨天我們在發布網站的過程中遇到了錯誤:

remote:        In Gemfile:
remote:        sqlite3
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3

heroku:「ㄉㄅㄑ,我不會用 sqlite3。」

所以我們必須移除 sqlite3 這個套件才行。

認識 Gemfile

Gemfile 在專案的根目錄下:

第12行寫著:gem 'sqlite3' 表示這個專案會使用 sqlite3 這個套件。套件是一群佛心來的人寫好後公開給大家用的程式。如果你想要安裝套件,就會需要在這裡加一行程式,如果想要移除某個套件,就要刪掉那一行程式。

這裡有所有能裝的套件:https://rubygems.org/gems。如果你想要成佛也可以在這裡貢獻一下你的程式。

每當修改過 Gemfile 之後,你要在小黑框輸入 bundle install。 bundle 是一個管理套件的套件,他會幫你下載套件程式碼。

如果你輸入 bundle install 之後看到的是這樣:

D:\只要有心,人人都可以作卡米狗\ironman>bundle install
'bundle' 不是內部或外部命令、可執行的程式或批次檔。

表示你的電腦沒有裝過 bundler,需要在小黑框輸入 gem install bundler 來安裝。

D:\只要有心,人人都可以作卡米狗\ironman>gem install bundler
Fetching: bundler-1.16.1.gem (100%)
Successfully installed bundler-1.16.1
Parsing documentation for bundler-1.16.1
Installing ri documentation for bundler-1.16.1
Done installing documentation for bundler after 20 seconds
1 gem installed 

移除 rails 專案中所使用的 sqlite3 套件

我們開始進行 sqlite3 的移除工作吧。

前面提到 Gemfile 第12行寫著:gem 'sqlite3',我們可以在這行的最前面加一個 # 號把這行變成註解,像這樣:

當然你要直接刪掉那行也不是不行啦,弄好之後記得存檔,存完檔之後,在小黑框輸入 bundle install

D:\只要有心,人人都可以作卡米狗\ironman>bundle
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Using activesupport 5.1.4
Using builder 3.2.3
Using erubi 1.7.0
Using mini_portile2 2.3.0
Using nokogiri 1.8.1 (x64-mingw32)
Using rails-dom-testing 2.0.3
Using crass 1.0.3
Using loofah 2.1.1
Using rails-html-sanitizer 1.0.3
Using actionview 5.1.4
Using rack 2.0.3
Using rack-test 0.8.2
Using actionpack 5.1.4
Using nio4r 2.2.0
Using websocket-extensions 0.1.3
Using websocket-driver 0.6.5
Using actioncable 5.1.4
Using globalid 0.4.1
Using activejob 5.1.4
Using mini_mime 1.0.0
Using mail 2.7.0
Using actionmailer 5.1.4
Using activemodel 5.1.4
Using arel 8.0.0
Using activerecord 5.1.4
Using public_suffix 3.0.1
Using addressable 2.5.2
Using bindex 0.5.0
Using bundler 1.16.1
Using byebug 9.1.0
Using xpath 2.1.0
Using capybara 2.16.1
Using ffi 1.9.18 (x64-mingw32)
Using childprocess 0.8.0
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.0
Using thor 0.20.0
Using railties 5.1.4
Using coffee-rails 4.2.2
Using multi_json 1.12.2
Using jbuilder 2.7.0
Using puma 3.11.0
Using sprockets 3.7.1
Using sprockets-rails 3.2.1
Using rails 5.1.4
Using rb-fsevent 0.10.2
Using rb-inotify 0.9.10
Using rubyzip 1.2.1
Using sass-listen 4.0.0
Using sass 3.5.4
Using tilt 2.0.8
Using sass-rails 5.0.7
Using selenium-webdriver 3.8.0
Using turbolinks-source 5.0.3
Using turbolinks 5.0.1
Using tzinfo-data 1.2017.3
Using uglifier 4.0.2
Using web-console 3.5.1
Bundle complete! 12 Gemfile dependencies, 66 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

D:\只要有心,人人都可以作卡米狗\ironman>

你會看到目前專案正在使用的所有套件。

進行本機測試

開啟 rails server 看看是否一切正常:

D:\只要有心,人人都可以作卡米狗\ironman>rails s
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.11.0 (ruby 2.4.2-p198), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

看似正常,開網頁 http://localhost:3000/ 看卻發現:

他說:「你的程式有用到 sqlite3,但是你沒有安裝 sqlite3,所以我又爆啦。」

我們在那裡用到了 sqlite3?

我們在 config/database.yml 中使用了 sqlite3

原來 sqlite3 是一個資料庫的套件,但是由於 heroku 不支援 sqlite3,所以我們必須找另一款 heroku 能支援的資料庫換上去,這裡我們要換的是 postgresql

改用 postgresql

我們需要把 config/database.yml 中第 8 行的 adapter: sqlite3 改為 adapter: postgresql

我們還需要安裝 postgresql 這個套件,這個套件叫 pg,所以修改 Gemfile 如下:

我在第 13 行寫 gem 'pg', '~> 0.21.0',其實要寫在第幾行都行。不過第 37 行有一個 group:

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :development, :test do 這行的意思是,只有在開發和測試環境下才需要安裝的套件。因為我們的 heroku 的環境是 :production,所以我們如果把 gem 'pg', '~> 0.21.0' 寫在這個 group 裡的話,heroku 就還是壞的。

其中~> 0.21.0 表示版本號,一個套件會隨著時間不斷更新,就像 iOS 和 Android 也會一直系統更新一樣。我們可以指定想要安裝的版本。

改完 Gemfile 之後,先關閉網頁伺服器,然後在小黑框輸入 bundle install 安裝新套件完之後再打開網頁伺服器。

再次進行本機測試

打開網頁:http://localhost:3000/

正常!

把改動後的程式碼上傳到 heroku

上傳到 heroku 之前要先建立一個 git 版本,之前提到過的上傳三步驟:

git add .
git commit -m "註解"
git push heroku master

如果你覺得註解亂寫沒關係的話,我是沒差,你可以直接複製上面三行程式碼到小黑框貼上。不過我就一步步來。

git add .

選擇所有檔案加入這次的版本:

D:\只要有心,人人都可以作卡米狗\ironman>git add .
warning: LF will be replaced by CRLF in Gemfile.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Gemfile.lock.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in config/database.yml.
The file will have its original line endings in your working directory.

git commit -m "改用pg"

建立一個版本,我的註解是寫 改用pg 說明我們這次的改動:

D:\只要有心,人人都可以作卡米狗\ironman>git commit -m "改用pg"
[master e6f3871] '改用pg'
 3 files changed, 5 insertions(+), 2 deletions(-)

D:\只要有心,人人都可以作卡米狗\ironman>

git push heroku master

上傳程式碼到 heroku:

D:\只要有心,人人都可以作卡米狗\ironman>git push heroku master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 297 bytes | 297.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: ###### WARNING:
remote:        Removing `Gemfile.lock` because it was generated on Windows.
remote:        Bundler will do a full resolve so native gems are handled properly.
remote:        This may result in unexpected gem versions being used in your app.
remote:        In rare occasions Bundler may not be able to resolve your dependencies at all.
remote:        https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
remote:        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`.
remote:        Fetching gem metadata from https://rubygems.org/..........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Resolving dependencies...
remote:        Using rake 12.3.0
remote:        Using concurrent-ruby 1.0.5
remote:        Using minitest 5.11.1
remote:        Using thread_safe 0.3.6
remote:        Using builder 3.2.3
remote:        Using erubi 1.7.0
remote:        Using mini_portile2 2.3.0
remote:        Using crass 1.0.3
remote:        Using rack 2.0.3
remote:        Using nio4r 2.2.0
remote:        Using websocket-extensions 0.1.3
remote:        Using mini_mime 1.0.0
remote:        Using arel 8.0.0
remote:        Using bundler 1.15.2
remote:        Using coffee-script-source 1.12.2
remote:        Using execjs 2.7.0
remote:        Using method_source 0.9.0
remote:        Using thor 0.20.0
remote:        Using ffi 1.9.18
remote:        Using multi_json 1.12.2
remote:        Fetching pg 0.21.0
remote:        Using puma 3.11.0
remote:        Using rb-fsevent 0.10.2
remote:        Using tilt 2.0.8
remote:        Using turbolinks-source 5.0.3
remote:        Using tzinfo 1.2.4
remote:        Using nokogiri 1.8.1
remote:        Using i18n 0.9.1
remote:        Using rack-test 0.8.2
remote:        Using sprockets 3.7.1
remote:        Using websocket-driver 0.6.5
remote:        Using mail 2.7.0
remote:        Using coffee-script 2.4.1
remote:        Using uglifier 4.1.2
remote:        Using rb-inotify 0.9.10
remote:        Using turbolinks 5.0.1
remote:        Using loofah 2.1.1
remote:        Using activesupport 5.1.4
remote:        Using sass-listen 4.0.0
remote:        Using rails-html-sanitizer 1.0.3
remote:        Using rails-dom-testing 2.0.3
remote:        Using globalid 0.4.1
remote:        Using activemodel 5.1.4
remote:        Using jbuilder 2.7.0
remote:        Using sass 3.5.5
remote:        Using actionview 5.1.4
remote:        Using activejob 5.1.4
remote:        Using activerecord 5.1.4
remote:        Using actionpack 5.1.4
remote:        Using actioncable 5.1.4
remote:        Using actionmailer 5.1.4
remote:        Using railties 5.1.4
remote:        Using sprockets-rails 3.2.1
remote:        Using coffee-rails 4.2.2
remote:        Using rails 5.1.4
remote:        Using sass-rails 5.0.7
remote:        Installing pg 0.21.0 with native extensions
remote:        Bundle complete! 13 Gemfile dependencies, 56 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (11.93s)
remote:        Cleaning up the bundler cache.
remote:        The latest bundler is 1.16.1, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler`
remote: -----> Installing node-v6.11.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        Asset precompilation completed (1.50s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote:
remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.3.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote:
remote: ###### WARNING:
remote:        Removing `Gemfile.lock` because it was generated on Windows.
remote:        Bundler will do a full resolve so native gems are handled properly.
remote:        This may result in unexpected gem versions being used in your app.
remote:        In rare occasions Bundler may not be able to resolve your dependencies at all.
remote:        https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: ###### WARNING:
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing...
remote:        Done: 36.7M
remote: -----> Launching...
remote:        Released v8
remote:        https://people-all-love-kamigo.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/people-all-love-kamigo.git
   e6f3871..5ec30ea  master -> master

D:\只要有心,人人都可以作卡米狗\ironman>

這次看似上傳成功了,從最後面往上看,倒數第 5 行有一個網址:https://people-all-love-kamigo.herokuapp.com/,以及三個 WARNING。

先不管 WARNING,我們複製網址進去看(你的網址會跟我的不同,取決於你之前下 heroku create 指令時輸入的網站名稱)。

Heroku說:「找不到網頁。」

這是因為在我們本機的首頁,其實是不在專案資料夾裡面的,記得一開始修改網頁(第九天:作一個最簡單的 Rails 網站)時,我們是去哪改嗎?是在 C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb,而這個檔案並不是在專案資料夾下,所以遠端伺服器沒有這個檔案也是很合邏輯的。

事實上,只有在 config/routes.rb 檔案裏面有寫到的那些路徑才是我們應該測的路徑,所以我們應該連到這裡:https://people-all-love-kamigo.herokuapp.com/kamigo/eat

吃土啦~

總結

程式碼除錯的流程大致上為:

  • 閱讀錯誤訊息
  • 修改程式碼
  • 測試網站,若失敗則回到第一步
  • 發布網站

工程師的日常就是除了一個錯之後看到的不是正常,而是看到下一個錯誤訊息。

要有耐心。


上一篇
第十八天:發布網站到 Heroku
下一篇
第二十天:串接 Line Messaging API Webhook
系列文
只要有心,人人都可以做卡米狗33
2
jerryw47
iT邦新手 5 級 ‧ 2018-01-07 10:29:21

想請問一下,我已經改成 adapter:postgresql,gem 'pg',輸入bundle install可是他卻出現這個錯誤訊息?
是install pg的問題嗎?要如何解決?
https://ithelp.ithome.com.tw/upload/images/20180107/20107956vfbKi6t6pq.png

看更多先前的回應...收起先前的回應...

gem 'pg' 不是 git 'pg'

可以貼上完整的訊息嗎?

https://ithelp.ithome.com.tw/upload/images/20180107/201079564j3qdN6ifN.png
https://ithelp.ithome.com.tw/upload/images/20180107/201079562XkandcKZO.png
https://ithelp.ithome.com.tw/upload/images/20180107/20107956FBBc6TnM9L.png
https://ithelp.ithome.com.tw/upload/images/20180107/20107956451Eprcx97.png
https://ithelp.ithome.com.tw/upload/images/20180107/20107956GHqL53FNSO.png
https://ithelp.ithome.com.tw/upload/images/20180107/20107956FAiSb44Cz4.png

試試看先下這個指令 brew install postgresql

成功了,感謝你

0
魷魚
iT邦新手 1 級 ‧ 2018-01-11 14:28:55

我發生跟上面那位蠻類似的狀況,但我是在Windows下操作https://ithelp.ithome.com.tw/upload/images/20180111/20103350R0B5lDS6RW.jpg

看資訊好像是有讀到postgresql,但沒有在gemfile裡面讀到gme 'pg',但是看起幾次看起來都是有正確輸入的。
※看了一下有bundle install,有看到pg 1.0.0 (x64-mingw32),現在有點卡關,再麻煩指導一下了QQ

windows 好像怪怪 der

請試著參考第二十三天:認識資料庫

先將開發環境的資料庫調整成 sqlite3

0
curry_sun
iT邦新手 5 級 ‧ 2018-01-27 17:38:58

https://ithelp.ithome.com.tw/upload/images/20180127/20108525KuJleVIs8C.png

請問要怎麼把前面的顯示時間換成GMT+8呢?
他顯示的時間跟台灣時區都不符...

0
nt31824
iT邦新手 5 級 ‧ 2018-03-12 11:05:56

卡米大請問
我在這個問題之後
https://ithelp.ithome.com.tw/upload/images/20180312/20108969u8IsuuRGxA.png
https://ithelp.ithome.com.tw/upload/images/20180312/20108969imEwqE78yx.png
https://ithelp.ithome.com.tw/upload/images/20180312/20108969638oG6gVxU.png
爬了留言去把開發環境的資料庫調整成 sqlite3
https://ithelp.ithome.com.tw/upload/images/20180312/20108969fHhMuHf184.png
https://ithelp.ithome.com.tw/upload/images/20180312/20108969YCjmOhYAlp.png
https://ithelp.ithome.com.tw/upload/images/20180312/20108969l5ndwKuUyH.png
卻還是一樣
https://ithelp.ithome.com.tw/upload/images/20180312/20108969wkWbhAsywF.png
https://ithelp.ithome.com.tw/upload/images/20180312/201089697dP85o2APa.png

在 database.yml 裡的描述是:
在 development 環境下要使用 sqlite3
在 test 環境下要使用 sqlite3
在 product 環境下要使用 postgresql

在你的 gemfile 裡的描述是:
在 development 環境下 不做事
在 test 環境下 不做事
在 product 環境下 要安裝 postgresql 套件

他不做事是因為你的 gemfile 第 15 行的最前面有一個 # ,#是註解的意思,代表這行有寫跟沒寫一樣,所以 # 要刪掉才行。

nt31824 iT邦新手 5 級‧ 2018-03-13 09:46:03 檢舉

這部分已排除~~
刪掉#之後,後來將db再同步一次搞定的

cool

1
mobetax52984
iT邦新手 5 級 ‧ 2018-04-16 21:28:08

https://ithelp.ithome.com.tw/upload/images/20180416/20109521OlaFtsRTc2.jpg

https://ithelp.ithome.com.tw/upload/images/20180416/20109521lpCk6vP649.jpg

請問這個狀況有辦法處理嗎?

看更多先前的回應...收起先前的回應...

確認一下是不是所有的縮排都是用半形空白

已確認全部編碼都是半形字體+半形空白 但出現一樣的錯誤訊息

我的借你抄看看:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  adapter: sqlite3
  encoding: big5
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  adapter: sqlite3
  encoding: big5
  database: db/test.sqlite3

production:
  <<: *default
  database: ironman

變成另外一個錯誤

https://ithelp.ithome.com.tw/upload/images/20180418/20109521V2fBv8FvAw.jpg

看一下你的 gemfile

https://ithelp.ithome.com.tw/upload/images/20180418/201095211hMwNi4CfX.jpghttps://ithelp.ithome.com.tw/upload/images/20180418/20109521iHtUOW8d4J.jpg

4/19出國 可能4/26回國再處理了 先謝謝卡米大了

請問 我的是不是沒救了...OTL

你參考這篇 https://ithelp.ithome.com.tw/articles/10196781

Gemfile 設定改一下你的 Gemfile 試試

好的 謝謝

2
laapnda
iT邦新手 5 級 ‧ 2018-04-26 00:38:30

不好意思 我又來了,我將gem 'sqlite3'加上#並輸入bundle install後 網站錯誤貌似不太一樣
https://ithelp.ithome.com.tw/upload/images/20180426/20109610FJlAB2YMy2.pnghttps://ithelp.ithome.com.tw/upload/images/20180426/20109610ardgOGrw5w.png
然而暫時放置不理 繼續步驟 該改的都做更改後 網站還是錯誤
https://ithelp.ithome.com.tw/upload/images/20180426/20109610yARLtqyVFd.pnghttps://ithelp.ithome.com.tw/upload/images/20180426/20109610iqqYcldD6y.pnghttps://ithelp.ithome.com.tw/upload/images/20180426/20109610ciJIZwoV5N.png

你先參考這篇的改法好了
https://ithelp.ithome.com.tw/articles/10196781

laapnda iT邦新手 5 級‧ 2018-04-27 00:13:20 檢舉

改完後已成功 非常感謝 麻煩了

0
陳同學
iT邦新手 5 級 ‧ 2018-05-16 15:50:52

https://ithelp.ithome.com.tw/upload/images/20180516/201088226D7uG2Agea.png
你好 這是我遇到的錯誤訊息 流程我都有按照你的步驟做了QAQ
補一點 這是我參考你第23篇的錯誤訊息
https://ithelp.ithome.com.tw/upload/images/20180516/20108822VP9JDuFZf2.png

看更多先前的回應...收起先前的回應...

請問你的 Gemfile 內容是什麼呢?

https://ithelp.ithome.com.tw/upload/images/20180516/20108822tMnOQ8P0Ag.png

第23篇提到 Gemfile 應該改成這樣:

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg', '~> 0.21.0'
end

詳細說明請見第23篇喔~

我改完之後,他就無法上傳到heroku
他會出現sqlite3無法上傳的錯誤,要怎麼處理

0
tarzan
iT邦新手 5 級 ‧ 2018-05-28 02:19:41

收到Heroku的通知:
The database contains 10,682 rows, exceeding the Hobby-dev plan limit of 10,000. INSERT privileges to the database will be automatically revoked in 7 days. This will cause service failures in most applications dependent on this database.
you should reduce the number of records stored in it.
怎麼作?

你可以考慮刪除不必要的資料 或者升級成付費資料庫

刪除資料的參考文件:https://ruby-china.github.io/rails-guides/active_record_basics.html#delete

資料庫價格表:https://www.heroku.com/pricing#databases

資料庫升級參考文件:https://andyyou.github.io/2017/09/29/upgrade-heroku-postgres/

tarzan iT邦新手 5 級‧ 2018-05-29 14:10:42 檢舉

謝謝卡米大

0
dannytan
iT邦新手 5 級 ‧ 2018-05-30 14:06:05

卡卡米大,麻煩你幫我解決我的問題了。感謝!我已經試過23篇的設定跟改還是出錯。https://ithelp.ithome.com.tw/upload/images/20180530/20105899DCznY5MO9P.pnghttps://ithelp.ithome.com.tw/upload/images/20180530/20105899V9wrYhK2vF.pnghttps://ithelp.ithome.com.tw/upload/images/20180530/201058992JcXphkXel.png

看更多先前的回應...收起先前的回應...
development:
  <<: *default
  adapter: sqlite3
  database: db/development.sqlite3

你的 adapter: sqlite3 不見了

改了之後變成這樣,抱歉還要再麻煩你了謝謝~https://ithelp.ithome.com.tw/upload/images/20180530/20105899F0FCmEbWUn.png

改了之後變成這樣,抱歉還要再麻煩你了謝謝~https://ithelp.ithome.com.tw/upload/images/20180530/20105899F0FCmEbWUn.png

我的gemfile黨是已經改過的了

根據錯誤訊息的內容,你應該是少做了這個步驟:

rails db:migrate

謝謝大大我解決了,但我想再問一個問題,在mac環境 請問首頁的index檔要去哪裡找,第九天教的,因為真的找不到那個位置

其實不應該改那個,如果真的想知道在哪,你可以開啟首頁,然後去看一下 logs 的紀錄,裡面會寫到 index 的路徑

0
rk42745417
iT邦新手 5 級 ‧ 2018-06-02 12:06:07

移除splite3 加入postgresql後發生的事情
https://ithelp.ithome.com.tw/upload/images/20180602/20110162xQL6wk4KLu.jpg
程式碼(抱歉習慣了notepad++):
https://ithelp.ithome.com.tw/upload/images/20180602/20110162qvIE41y5Pw.jpg
https://ithelp.ithome.com.tw/upload/images/20180602/20110162ldrKLFvNcq.jpg

不知為何你會在此時遇到這個問題,但遇到的話 建議 資料庫設定的部分就直接跳到第23天的作法好了

0
patyhank
iT邦新手 5 級 ‧ 2018-07-05 14:14:22

我也遇到PG::ConnetionBad的錯誤但我照著23天做會出現
https://ithelp.ithome.com.tw/upload/images/20180705/201086653gMTvi6QL3.png
請問要怎麼辦

這個你要下 rails db:migrate 指令

請問一下這是甚麼意思

C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/dsl.rb:586:in `parse_line_number_from_description': incompatible encoding regexp match (CP950 regexp with ASCII-8BIT string) (Encoding::CompatibilityError)
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/dsl.rb:552:in `to_s'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/setup.rb:12:in `message'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/setup.rb:12:in `rescue in <top (required)>'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/setup.rb:9:in `<top (required)>'
        from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `require'
        from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
        from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from C:/Users/paty2/Desktop/只要有心,人人都可以用卡米狗/ironman/config/boot.rb:3:in `<top (required)>'
        from bin/rails:3:in `require_relative'
        from bin/rails:3:in `<main>'

打完之後再啟動就出現了

最後決定重來拉

0
patyhank
iT邦新手 5 級 ‧ 2018-07-05 21:18:54

請問上傳herkou時出現這問題要怎麼辦
報錯:

remote:        In Gemfile:
remote:          sqlite3
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to patyhank-bot-line.
remote:
To https://git.heroku.com/patyhank-bot-line.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/patyhank-bot-line.git'
看更多先前的回應...收起先前的回應...

剛剛留錯的

這篇文章就是在講怎麼解決這個問題喔 請看到這篇文章的一開始 是不是跟你的錯誤訊息一模一樣呢

我是翻了23篇的資料庫解決PG:BAD...的錯誤
結果就出現了

結果是我沒把 gem 'sqlite3' 刪掉

在第23天的文章中並沒有把 gem 'sqlite3' 刪掉哦

第23天的文章說,要改成這樣:

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg', '~> 0.21.0'
end

gem 'sqlite3' 還在喔 只是不給 heroku 用了

可是不刪就無法上傳

重點是在 group :development, :test do 跟 group :production do ,你這段沒寫的話就會無法上傳

0
such0305
iT邦新手 5 級 ‧ 2018-07-08 12:20:48

問題已自行解決,感恩卡米大大的保佑!

0
001on99487
iT邦新手 5 級 ‧ 2018-07-21 21:10:28

這個要怎處理,求救
ActiveRecord::PendingMigrationError

Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development

輸入 rails db:migrate

0
001on99487
iT邦新手 5 級 ‧ 2018-07-23 21:21:10

! No default language could be detected for this app.
HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
See https://devcenter.heroku.com/articles/buildpacks

! Push failed
這個要怎處理,求救

請問你作到哪一步驟看到這個?

上傳程式碼到 heroku 那時候看到的

你有做 git commit 嗎?

0
robert0397
iT邦新手 5 級 ‧ 2018-08-07 12:45:21

大大您好

目前我也已經改成 adapter:postgresql,gem 'pg',一樣輸入bundle install卻也出現這個
安裝pg問題
也試過brew install postgresql和brew link postgresql了
但一樣輸入bundle install 就是有pg的問題...

謝謝

看更多先前的回應...收起先前的回應...

附上目前改gemfile和database的狀況
gemfile

database

試試 gem 'pg', '~> 0.21.0'

解決了 謝謝
我是上網找到,好像是權限的問題
https://wtnvenga.hatenablog.com/entry/2017/11/15/125430
在輸入brew link postgresql做連結的時候
出現/usr/local/share/man/man7 不可以寫
所以cd /usr/local/share/man 先跳到這個位置
然後輸入sudo chown -R $USER man7 給man7有寫的權利

差不多這樣 分享給需要的人!

太神啦

0
freyr949487
iT邦新手 5 級 ‧ 2018-11-02 23:26:18

上傳完後反而變成這樣!https://ithelp.ithome.com.tw/upload/images/20181102/20110243fBnYxqUT6T.png

https://ithelp.ithome.com.tw/upload/images/20181102/20110243z1LRc9e6UV.png

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.4.4

WARNING:
   Removing `Gemfile.lock` because it was generated on Windows.
   Bundler will do a full resolve so native gems are handled properly.
   This may result in unexpected gem versions being used in your app.
   In rare occasions Bundler may not be able to resolve your dependencies at all.
   https://devcenter.heroku.com/articles/bundler-windows-gemfile

-----> Installing dependencies using bundler 1.15.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4
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 gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.3.1
Using concurrent-ruby 1.0.5
Using minitest 5.11.3
Using thread_safe 0.3.6
Using builder 3.2.3
Using erubi 1.7.1
Using mini_portile2 2.3.0
Using crass 1.0.4
Using rack 2.0.5
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using mini_mime 1.0.1
Using arel 9.0.0
Using mimemagic 0.3.2
Using msgpack 1.2.4
Using bundler 1.15.2
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using method_source 0.9.0
Using thor 0.20.0
Using duktape 2.0.1.0
Using ffi 1.9.25
Using multi_json 1.13.1
Using pg 0.21.0
Using puma 3.12.0
Using rb-fsevent 0.10.3
Using tilt 2.0.8
Using turbolinks-source 5.2.0
Using i18n 1.1.1
Using tzinfo 1.2.5
Using nokogiri 1.8.5
Using rack-test 1.1.0
Using sprockets 3.7.2
Using websocket-driver 0.7.0
Using mail 2.7.1
Using marcel 0.3.3
Using bootsnap 1.3.2
Using uglifier 4.1.19
Using coffee-script 2.4.1
Using rb-inotify 0.9.10
Using activesupport 5.2.1
Using turbolinks 5.2.0
Using loofah 2.2.3
Using rails-dom-testing 2.0.3
Using globalid 0.4.1
Using activemodel 5.2.1
Using jbuilder 2.7.0
Using sass-listen 4.0.0
Using activejob 5.2.1
Using rails-html-sanitizer 1.0.4
Using activerecord 5.2.1
Using actionview 5.2.1
Using actionpack 5.2.1
Using sass 3.6.0
Using actioncable 5.2.1
Using actionmailer 5.2.1
Using activestorage 5.2.1
Using railties 5.2.1
Using sprockets-rails 3.2.1
Using coffee-rails 4.2.2
Using rails 5.2.1
Using sass-rails 5.0.7
Bundle complete! 17 Gemfile dependencies, 62 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into ./vendor/bundle.
Bundle completed (3.46s)
Cleaning up the bundler cache.
The latest bundler is 1.17.1, but you are currently running 1.15.2.
To update, run gem install bundler
-----> Installing node-v8.10.0-linux-x64
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
Asset precompilation completed (1.11s)
Cleaning assets
Running: rake assets:clean
-----> Detecting rails configuration

WARNING:
   Removing `Gemfile.lock` because it was generated on Windows.
   Bundler will do a full resolve so native gems are handled properly.
   This may result in unexpected gem versions being used in your app.
   In rare occasions Bundler may not be able to resolve your dependencies at all.
   https://devcenter.heroku.com/articles/bundler-windows-gemfile
WARNING:
   Detecting rails configuration failed
   set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
WARNING:
   We detected that some binary dependencies required to
   use all the preview features of Active Storage are not
   present on this system.
   
   For more information please see:
     https://devcenter.heroku.com/articles/active-storage-on-heroku
   
WARNING:
   No Procfile detected, using the default web server.
   We recommend explicitly declaring how to boot your server process via a Procfile.
   https://devcenter.heroku.com/articles/ruby-default-web-server

-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> console, rake, web
-----> Compressing...
Done: 43.2M
-----> Launching...
Released v7
https://people-all-lovel-jeanne.herokuapp.com/ deployed to Heroku

在本機上是正常運作的嗎?

正常運作 rails是可以開啟的 但heroku上傳失敗
且H10為APP Crash

米大有方法解決嗎?

0
gordonjohn12
iT邦新手 5 級 ‧ 2018-12-05 16:53:40

米大想請問,我現在做到"再次進行本機測式",因為發生問題,也已經照著23天的改法把gemfile及database改過了,但是要重新'bundle install'時,好像找不到'sqlites3 x64-mingw32'。想請問不知道是哪個環節出錯了,謝謝

https://ithelp.ithome.com.tw/upload/images/20181205/20113819Ry62PWdXHu.jpg
https://ithelp.ithome.com.tw/upload/images/20181205/20113819FT96JVeWTv.jpg
https://ithelp.ithome.com.tw/upload/images/20181205/20113819tNB7tbBgcu.jpg

0
s102213039
iT邦新手 5 級 ‧ 2018-12-27 14:45:41

如果有下圖這樣問題的人(借個圖)

有可能是你之前就有用git且有設定全域的.gitignore,所以"有機會"忽略到該上傳的資料夾或是檔案,以我的情況為例,我的sourcetree自動忽略了bin資料夾,導致app crash,你只要把bin重新上傳到heroku就可以正常運行了。(至於你的全域.gitignore在哪你就要自己找了......)

參考:
https://stackoverflow.com/questions/13496827/heroku-deployment-error-h10-app-crashed

0
cool_light99
iT邦新手 5 級 ‧ 2018-12-27 23:09:31

版大,照文教學我改了Gemfile,database.yml之sqlite3再重新bundle install,網頁就變純文字錯誤畫面了....請教是那邊有問題
https://ithelp.ithome.com.tw/upload/images/20181227/20114225cubyo2k3co.jpghttps://ithelp.ithome.com.tw/upload/images/20181227/20114225JtK4TPRnKH.jpghttps://ithelp.ithome.com.tw/upload/images/20181227/201142250QAExAUeUl.jpg

已解決

我要留言

立即登入留言