iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 9
24
Modern Web

只要有心,人人都可以做卡米狗系列 第 9

第九天:作一個最簡單的 Rails 網站

我們今天終於可以開始作網站了,首先我們要找一個地方放我們網站的程式碼。

建立一個 Rails 網站

先開啟檔案總管(Windows+E),移動到 D:\只要有心,人人都可以作卡米狗 這個資料夾下。

然後在網址列輸入 cmd 開啟小黑框。

我們要在這個資料夾建立一個名叫 ironman 的網站。

在小黑框輸入 rails new ironman

然後按下 Enter

D:\只要有心,人人都可以作卡米狗>rails new ironman
      create
      create  README.md
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."
Initialized empty Git repository in D:/只要有心,人人都可以作卡米狗/ironman/.git/
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/javascripts/application.js
      create  app/assets/javascripts/cable.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images/.keep
      create  app/assets/javascripts/channels
      create  app/assets/javascripts/channels/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/update
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/cable.yml
      create  config/puma.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_5_1.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  tmp
      create  tmp/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  package.json
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_5_1.rb
         run  bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies.....
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.0
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 sqlite3 1.3.13 (x64-mingw32)
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! 13 Gemfile dependencies, 67 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

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

這邊可以先不用細讀,如果看到跟我的很像的話就是順利,不順利的人可以截圖在本文留言。

一個最簡單的網站就這樣作好了!

看看建立的網站

先用 dir /w ,可以看到多了一個資料夾叫作 ironman

D:\只要有心,人人都可以作卡米狗>dir /w
 磁碟區 D 中的磁碟是 GG
 磁碟區序號:  D403-9A5D

 D:\只要有心,人人都可以作卡米狗 的目錄

[.]               [..]              [ironman]         新文字文件.html
               1 個檔案              37 位元組
               3 個目錄  1,590,464,393,216 位元組可用

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

再用 cd ironman 移動到專案資料夾目錄下。

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

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

再用 dir /w 看資料夾內容。

D:\只要有心,人人都可以作卡米狗\ironman>dir /w
 磁碟區 D 中的磁碟是 GG
 磁碟區序號:  D403-9A5D

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

[.]            [..]           .gitignore     [app]          [bin]          [config]
config.ru      [db]           Gemfile        Gemfile.lock   [lib]          [log]
package.json   [public]       Rakefile       README.md      [test]         [tmp]
[vendor]
               7 個檔案           7,601 位元組
              12 個目錄  1,590,464,393,216 位元組可用

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

這就是剛剛的 rails new ironman 幫我們建立的檔案們。他自動生成了一個 rails 專案所需要的檔案,以及安裝相關的套件。好消息是這麼多資料夾和檔案,現階段我們都不需要認識。

執行網頁伺服器

我們直接用 rails server 執行網站伺服器。(注意:rails server 必須在專案資料夾執行才有效)

D:\只要有心,人人都可以作卡米狗\ironman>rails server
=> 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

看到第一行 Booting Puma 這就是我之前說的 Puma 網頁伺服器。再看到最後面有一行 Listening on tcp://0.0.0.0:3000 是重點,看到這行表示 server 已經在運作了。

用瀏覽器連網頁伺服器

這時候你開啟這個網址:http://127.0.0.1:3000 或者這個網址:http://localhost:3000/ 就會看到你的網站。

網站長這樣:

我可沒有要給你看我的初音主題哦。

回去看看小黑框,上面多了一些字像這樣:

Started GET "/" for 127.0.0.1 at 2017-12-28 01:57:53 +0800
Processing by Rails::WelcomeController#index as HTML
  Rendering C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb
  Rendered C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb (2.5ms)
Completed 200 OK in 65ms (Views: 29.9ms)

每當你開啟一次 http://localhost:3000/,你就會看到多了一些字在小黑框上,這代表有人正在下載我們的網頁檔案。

網頁伺服器運作過程

這裡我們仔細讀一下看他寫些什麼,只有五行不難讀。

Started GET "/" for 127.0.0.1 at 2017-12-28 01:57:53 +0800

這表示有客人在瀏覽器輸入了 http://localhost:3000/ 透過網路連線過來了,他來我們拿一個檔案。

Processing by Rails::WelcomeController#index as HTML

我們這邊的服務生是由 Rails::WelcomeController#index 來作服務。

Rendering C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb

服務生決定拿 C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb 這個檔案的執行結果給客戶。

把網頁搞爆

為了證明這是你的網站,我們要修改一個檔案,來影響這個網站的畫面。

我們開一個新的檔案總管(Windows+E),並在網址列輸入C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/templates/rails/welcome/ (注意:你的路徑可能跟我的不同)。

嗯...為了避免初心者幼小的心靈遭受到巨大的打擊,我們千萬不要打開這個檔案。

我們先備份一下這個檔案,備份檔案的方式是新增一個資料夾叫備份

然後把現在的這個 index.html.erb 用滑鼠拖曳的方式丟進備份資料夾裡。

丟進去之後這裡就沒有 index.html.erb 這個檔案了。

這時候我們再開一次網頁 http://localhost:3000/

恭喜你獲得了 第一次把網站搞爆就上手 的成就。

因為他找不到 index.html.erb 這個檔案,所以就◢▆▅▄▃_崩╰(〒皿〒)╯潰_▃▄▅▆◣惹。

其實到這邊就已經證明了,http://localhost:3000/ 這個網站真的是在我們的電腦上。

把網頁修好

這時我們要把他修好,我們在第六天:認識網站有學過怎麼作網頁。

我們在這裡新增一個文字檔,並直接改名叫 index.html,再次開啟 http://localhost:3000/

就會看到一個空白畫面。耶,我們把網站修好了。

關閉網頁伺服器

我們回到小黑框,按下 Ctrl+C

- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2017-12-28 02:48:28 +0800 ===
- Goodbye!
Exiting
要終止批次工作嗎 (Y/N)?

這邊輸入YEnter,網頁伺服器就被關掉了,這時候再去開網頁會看到什麼呢? http://localhost:3000/

結論

  • 今天學會了怎麼作一個最簡單的 Rails 網站
  • 今天學會執行和關閉網頁伺服器
  • 還不知道為什麼 http://localhost:3000/ 可以連到網站
  • 還不知道為什麼在自己作的網站打中文,網站就會掛掉

如果你有偷偷研究,你會發現在我們作的網頁裡面放英文沒事,但放中文就會壞掉,明天講怎麼解決這個問題。


上一篇
第八天:安裝 Rails 和認識小黑框
下一篇
第十天:認識文字編碼
系列文
只要有心,人人都可以做卡米狗33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
6
taiansu
iT邦新手 4 級 ‧ 2017-12-28 04:28:59

居然做 Windows 的教學範例,敬佩!/images/emoticon/emoticon69.gif

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

因為大家都寫 MacOS 的,但是我廣大的粉絲群應該沒有 Mac。

Summer iT邦新手 3 級 ‧ 2017-12-28 09:45:36 檢舉

我也是 windows XD

windows用戶在這裡XDDDDDD
我也沒有MAC沒錢錢XD

那請問大大,在Mac新增ironman網站要在terminal打什麼

小魚 iT邦大師 1 級 ‧ 2018-11-27 17:30:44 檢舉

Windows用戶路過, 總算看完 1/3了

XD

2
jacky860328
iT邦新手 5 級 ‧ 2018-02-07 10:06:41

請問大大,在Mac新增ironman網站要在terminal打什麼

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

如果你已經安裝好了 rails,指令一樣是rails new ironman 哦。

如果你想要在安裝 rails 的話可以參考這篇:為你自己學 Ruby on Rails - 02 開發環境安裝

卡米大可是他不理我QQ
點進去~~

你的指令怎麼多了一個路徑在前面@@

我學你在第三張圖的動作derrr~~

我學你在第三張圖的動作derrr~~

我沒有阿QQ

欸!!?所以前面的“D:/只要有心,人人都可以做卡米狗”不是一個路徑囉?那我要怎麼在我的“Test網站201802”增加ironman網站

應該不會只有打“rails new ironman”對吧~~?

setmao iT邦新手 5 級 ‧ 2018-02-08 14:26:11 檢舉

只要打rails new ironman就好了喔,依照教學是你要先用cd指令將當前目錄移到你想要放rails專案的目錄底下再用rails new ironman來建立一個新的rails專案

簡單來說:

  1. cd /Users/jacky860328/Desktop/Test網站201802
  2. rails new ironman
setmao iT邦新手 5 級 ‧ 2018-02-08 14:26:22 檢舉

只要打rails new ironman就好了喔,依照教學是你要先用cd指令將當前目錄移到你想要放rails專案的目錄底下再用rails new ironman來建立一個新的rails專案

簡單來說:

  1. cd /Users/jacky860328/Desktop/Test網站201802
  2. rails new ironman

感謝setmao的回應

謝謝各位大大的指教QQQQQ

3
nt31824
iT邦新手 5 級 ‧ 2018-03-10 21:04:06

https://ithelp.ithome.com.tw/upload/images/20180310/20108969nmzXIfZEKo.png
卡米大 請問 執行網頁伺服器 這裡點擊網址出現圖中問題 請問是什麼意思?

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

本文中已經有提到怎麼解決問題,恭喜你獲得了第一次把網站搞爆就上手的成就。

nt31824 iT邦新手 5 級 ‧ 2018-03-10 23:49:33 檢舉

感謝大大提示 但我做了一個新的HTML 他還是一樣呢
不好意思 第一次接觸 問題比較多

你做的 html 檔名是什麼?還有你的小黑框截圖可以附一張網頁開啟後的嗎?

nt31824 iT邦新手 5 級 ‧ 2018-03-11 10:26:14 檢舉

https://ithelp.ithome.com.tw/upload/images/20180311/20108969pu1kRNkMII.png
這是我目前的狀況

nt31824 iT邦新手 5 級 ‧ 2018-03-11 10:34:25 檢舉

https://ithelp.ithome.com.tw/upload/images/20180311/20108969WqRPf31gkc.png

https://ithelp.ithome.com.tw/upload/images/20180311/20108969wLT3k695H1.png

https://ithelp.ithome.com.tw/upload/images/20180311/201089690ffVh451Mm.png

nt31824 iT邦新手 5 級 ‧ 2018-03-11 10:54:08 檢舉

https://ithelp.ithome.com.tw/upload/images/20180311/2010896985jx07Zt8W.png

你在下 rails server 指令之前應該要先檢查你的小黑框所在的目錄
你要在專案資料夾下輸入 rails server,才能正常執行

在你開啟 http://localhost:3000/ 網頁時,看到的是無法連上這個網站,表示你的網頁伺服器沒有正常運作。

nt31824 iT邦新手 5 級 ‧ 2018-03-11 20:52:44 檢舉

謝謝卡米大 我再試試

nt31824 iT邦新手 5 級 ‧ 2018-03-11 22:45:47 檢舉

這是我的步驟
https://ithelp.ithome.com.tw/upload/images/20180311/20108969nBguReLIuz.png
https://ithelp.ithome.com.tw/upload/images/20180311/20108969BDkuxzefvY.png
https://ithelp.ithome.com.tw/upload/images/20180311/20108969VaQTz7u7vs.png
https://ithelp.ithome.com.tw/upload/images/20180311/2010896976hw6DThpC.png
https://ithelp.ithome.com.tw/upload/images/20180311/20108969ackBM2mf2q.png
到這邊之後他就跳這樣
https://ithelp.ithome.com.tw/upload/images/20180311/20108969DsszJmKnTl.png
https://ithelp.ithome.com.tw/upload/images/20180311/20108969bnjkS0ze20.png
上面這兩個應該就是卡米大說的搞爆步驟,但我才剛開始運作 然後點網址就變成這樣
就算用了修復網站那個動作,還是一樣的結果 再請卡米大幫我
非常感謝

nt31824 iT邦新手 5 級 ‧ 2018-03-11 23:49:02 檢舉

回報 問題已排除,是附檔名大寫的關係

恭喜修 bug 成功

0
nt31824
iT邦新手 5 級 ‧ 2018-03-10 21:06:54

https://ithelp.ithome.com.tw/upload/images/20180310/20108969ZzSNvzoStl.png
這是未點網址之前CMD的內容

0
x90124013
iT邦新手 5 級 ‧ 2018-04-06 05:16:09

卡米大您好
我在輸入rails server以後
一直出現錯誤訊息 希望您可以替我解答
https://ithelp.ithome.com.tw/upload/images/20180406/20109388BsAEtuic9t.png

看更多先前的回應...收起先前的回應...
x90124013 iT邦新手 5 級 ‧ 2018-04-06 16:34:42 檢舉

已自行解決,ruby版本問題

cool

https://imgur.com/Agmt1dN
請問是怎麼解決的嗎
是重新安裝ruby跟rails嗎

sky54063 iT邦新手 5 級 ‧ 2019-04-09 18:26:57 檢舉

請問 是如何解決的呢
我也是遇到相同問題

1
ethan0707
iT邦新手 5 級 ‧ 2018-04-18 23:24:08

https://ithelp.ithome.com.tw/upload/images/20180418/201095523itK2HPZoa.png
請問大大,我確定我是在專案資料夾下輸入rails server,也重新安裝rudy以及rails了,但還是有以上的錯誤出現,請問大大要怎麼排除呢 ?謝謝

看更多先前的回應...收起先前的回應...
ethan0707 iT邦新手 5 級 ‧ 2018-04-19 12:46:32 檢舉

已排除

ksml9207 iT邦新手 5 級 ‧ 2018-08-28 11:15:35 檢舉

請問是如何排除的

資料夾名稱改成英文的

ksml9207 iT邦新手 5 級 ‧ 2018-09-06 14:02:57 檢舉

謝謝

0

米大 我把 C:\Ruby24-x64\lib\ruby\gems\2.4.0\gems\railties-5.2.0\lib\rails\templates\rails\welcome 這邊路徑的 index.html.erb 用ctrl+z搞砸了
後面我就算改副檔名也無法回復成之前的樣子 之前我成功了 但是搞砸後 我重灌也沒用QAQ

不明 檢舉
【**此則訊息已被站方移除**】
gem install railties 5.2.0
不明 檢舉
【**此則訊息已被站方移除**】
0
fuga
iT邦新手 5 級 ‧ 2018-07-03 12:27:04

https://imgur.com/a/9eQd3LZ
https://imgur.com/a/1lqRi34
大大請問有哪邊出問題嗎?

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

哇 我也沒看過這個耶QQ

fuga iT邦新手 5 級 ‧ 2018-07-04 21:36:27 檢舉

挖 害阿哈哈

fuga iT邦新手 5 級 ‧ 2018-07-04 21:43:09 檢舉

可以加大大的Line嗎
感覺比較方便問問題~

在這裡回答問題的話 可以解決比較多人的問題

fuga iT邦新手 5 級 ‧ 2018-07-05 13:13:11 檢舉

了解

fuga iT邦新手 5 級 ‧ 2018-07-09 17:58:31 檢舉

大大問一下喔
第三天那個賴機器人可以看別人私人回應嗎

不能。

fuga iT邦新手 5 級 ‧ 2018-07-13 17:15:49 檢舉

就是別人對機器人說的話不能看到嗎030

如果你是想要用 Line@ App 去看的話,不能。

但你可以使用你的資料庫去記錄所有人講的話,然後再另外做一個網頁,或者聊天機器人的功能,去顯示你資料庫的紀錄。

0
NiMa
iT邦新手 5 級 ‧ 2018-10-26 14:16:30

https://ithelp.ithome.com.tw/upload/images/20181026/20112850WeQL602QAY.jpg
我在打完rails new ironman 出現這個
想請問一下要如何解決??

0
charlie1219
iT邦見習生 ‧ 2018-12-03 00:46:00

https://imgur.com/a/PBxAadP
https://imgur.com/a/SsLbWM9

求助大大
這樣該怎麼解決

你不要打 http 後面的 s

0
j581231c
iT邦新手 5 級 ‧ 2018-12-14 18:26:16

先感謝大大的教學,請問這裡為什麼卡住了。
https://imgur.com/iqY0XMC

https://github.com/sparklemotion/sqlite3-ruby/issues/240

試試

gem uninstall sqlite3 --all
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem inst sqlite3 --platform ruby
j581231c iT邦新手 5 級 ‧ 2018-12-14 21:19:56 檢舉

版主不好意思,試了之後還是跑出這個。還因為是我版本的問題?
https://imgur.com/HoAuZ6J
https://imgur.com/LgLRCia

0
cool_light99
iT邦新手 5 級 ‧ 2018-12-24 23:19:46

請教大大,我執行rails server,出現 Permission denied,不知怎麼解?
https://ithelp.ithome.com.tw/upload/images/20181224/20114225oiPlEfC7Qr.jpg

是輸入 rails server 不是輸入 ruby bin/rails server

已解決,是權限問題^^

/images/emoticon/emoticon12.gif

1
janice_kuo
iT邦新手 5 級 ‧ 2019-02-08 22:58:27

https://imgur.com/a/WYmzdSm
我的結果好像有一點不一樣

vul3865 iT邦新手 5 級 ‧ 2019-02-10 18:21:10 檢舉

我昨天也是看到這篇發現同樣問題,照下面的方式
https://github.com/sparklemotion/sqlite3-ruby/issues/241
更改完gemfile內的sqlite3參數為
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"

存檔,小黑框輸入bundle install讓它安裝一次就可以rails s了,可以試試看

謝謝

0
ariesbaby116
iT邦新手 5 級 ‧ 2019-02-12 18:32:27

https://imgur.com/a/cuF4hKT
請問我執行網頁伺服器出現這個 找不到OOXX元件怎麼排除?

1
iT邦新手 5 級 ‧ 2019-02-13 20:24:09

在進行rails new 的過程中不斷出現這個錯誤,請問我該如何解決?
https://ithelp.ithome.com.tw/upload/images/20190213/20111939r4zplMwO7S.png

vul3865 iT邦新手 5 級 ‧ 2019-02-15 19:39:32 檢舉

這個跟上面janice_kuo問的問題一樣的 找不到sqlite3的元件
可以照上面方式做做看

0
waynesir19
iT邦新手 5 級 ‧ 2019-04-04 00:17:35

https://ithelp.ithome.com.tw/upload/images/20190404/20116668UFkjIy0ToV.jpg

想請教這個問題,輸入rails servers時候出現這個訊息,該如何排除呢?
謝謝

https://ithelp.ithome.com.tw/upload/images/20190405/20116668UjW1LkrQEz.jpg

求助大大,他好像變得更加嚴重了一些,
我重新安裝了Ruby2.6.1-1 x64 跟 Rails,
現在跑出這一長串錯誤,
請求大神解答~謝謝

我也遇到一樣的問題@@
我已經把gemfile內調整成gem 'sqlite3', '1.3.13' ,也bundle install了,但是在輸入rails server後會出現
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

請求大大教學QQQ

請問樓上大大後來有排除嗎

0
fateclan05
iT邦見習生 ‧ 2019-04-28 16:56:21

在輸入rails new ironmen之後出現這個錯誤
想請教該如何排除?感謝
https://i.imgur.com/yP9hmBU.png

0
cheu1234
iT邦新手 5 級 ‧ 2019-05-13 21:13:30

我已經做到第19天了,因為有問題爬文後也參考第23天的改法,執行rails server後網頁顯示正常
然後準備要做第20天時執行rails server後就出現這樣了,請問哪裡出了問題
https://ithelp.ithome.com.tw/upload/images/20190513/20117585WvFitFru9X.png
麻煩你替我解答,謝謝!!

這要看一下你的 routes.rb 裡面寫了什麼

0
darrendarren
iT邦新手 5 級 ‧ 2019-05-15 19:19:11

大大請問我已經把gemfile內調整成gem 'sqlite3', '1.3.13' ,也bundle install了,但是在輸入rails server後會出現
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

請求大大教學QQQ

試試看改用ruby2.4

有了 這樣就可以了 非常感謝

1
willy90796
iT邦新手 5 級 ‧ 2019-05-22 21:25:03

https://imgur.com/L5u0SbY
https://imgur.com/L5u0SbY
我是超級新手,完全照本宣科
執行到「用 rails server 執行網站伺服器」之後變這樣
不知道甚麼問題,也不知道怎麼研究解決@@

有人能解答嗎@@

解決了,謝謝
不過其實看了很久都沒搞懂
後來才明白要用記事本打開去修內容

1
default_value
iT邦新手 5 級 ‧ 2019-07-01 15:58:51

在輸入rails new ironmen跟修改user權限之後出現這個錯誤
想請教大大該如何排除?感謝https://ithelp.ithome.com.tw/upload/images/20190701/20118706Sq49RErj8t.png

疑 你的資料夾路徑是錯的,你不能在 C:\WINDOWS\System32 底下建立你的專案,你應該要先切換到其他硬碟,如果你有其他硬碟的話。

如果沒有其他硬碟,你可以考慮在 C: 根目錄下建立你的專案。

最後專案放在d槽有ironman 也修正gem 'sqlite3', '1.3.13'
但在專案資料夾下輸入指令時有點卡關,不知道該怎麼做?
D:>D:\記帳貓貓\ironman>bundle install
'D:\記帳貓貓\ironman' 不是內部或外部命令、可執行的程式或批次檔。

你要輸入的是bundle install,不是 D:\記帳貓貓\ironman>bundle install

0
passerby9999
iT邦新手 5 級 ‧ 2019-08-23 02:03:06

https://ithelp.ithome.com.tw/upload/images/20190823/20120082aSav1b4lqV.jpg

請問我再執行rails server會跳出這個警示,請問我該如何處理,麻煩您

1
fuga
iT邦新手 5 級 ‧ 2019-08-27 22:58:14

進行到這邊。
執行網頁伺服器
我們直接用 rails server 執行網站伺服器。(注意:rails server 必須在專案資料夾執行才有效)
https://imgur.com/a/WuxZgn6

0
fuga
iT邦新手 5 級 ‧ 2019-08-30 13:10:46

https://imgur.com/a/2sl0YQ8
想請問已經修改後還是出現
https://imgur.com/a/Dp68hLm
需要怎麼處理!

你修改後有重新執行 bundle install 嗎?

0
sa0628
iT邦新手 5 級 ‧ 2019-10-06 17:24:14

感謝大大分享
https://ibb.co/V01p6Rj
請問這個問題怎辦QQ

你需要先安裝rails 你可以看一下第八天之前的文章

0
zx1478963310
iT邦新手 5 級 ‧ 2019-10-15 23:46:00

這邊可以先不用細讀,如果看到跟我的很像的話就是順利,不順利的人可以截圖在本文留言。
請問這邊不一樣,如何解決https://ithelp.ithome.com.tw/upload/images/20191015/20122174Jj71sGboNR.png

請參考:https://medium.com/@EtrexKuo/%E5%9C%A8-windows-%E4%B8%8A%E4%BD%BF%E7%94%A8-rails-gemfile-%E5%AE%89%E8%A3%9D-sqlite3-1-4-0%E5%A4%B1%E6%95%97%E6%99%82%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95-b8ac63e05bb2

0
jackiechung
iT邦新手 5 級 ‧ 2019-11-14 09:27:39

您好,
我在Win10安裝的是devkit-2.6.5-1-x64,
在CMD執行rails new ironman時發現錯誤,畫面如下:
https://imgur.com/RTD9DeU
請問該如何排除呢?
謝謝你

請參考:https://medium.com/@EtrexKuo/%E5%9C%A8-windows-%E4%B8%8A%E4%BD%BF%E7%94%A8-rails-gemfile-%E5%AE%89%E8%A3%9D-sqlite3-1-4-0%E5%A4%B1%E6%95%97%E6%99%82%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95-b8ac63e05bb2

0
q3571594628
iT邦新手 5 級 ‧ 2019-11-19 01:32:59

你好 我在現在是用Ruby+Devkit 2.5.7-1 (x64)版本
因為我用Ruby+Devkit 2.4.9-1 (x64)這個版本他跟我說要>=2.5.0
然後我在執行rails server的時候出現下面的圖
https://imgur.com/a/fpY9gQL
請問這樣怎麼解決

請參考:https://medium.com/@EtrexKuo/%E5%9C%A8-windows-%E4%B8%8A%E4%BD%BF%E7%94%A8-rails-gemfile-%E5%AE%89%E8%A3%9D-sqlite3-1-4-0%E5%A4%B1%E6%95%97%E6%99%82%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95-b8ac63e05bb2

2
cow03haha
iT邦新手 5 級 ‧ 2019-12-18 17:32:48
C:\Users\admin\Desktop\line chat bot>rails new noobcow
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."

C:\Users\admin\Desktop\line chat bot>

大大我創建新的rails只會跑出這些,有解嗎QQ

這是我的版本

ruby:
  path: C:/Ruby26-x64
  version: 2.6.5
  platform: x64-mingw32
ruby_installer:
  package_version: 2.6.5-1
  git_commit: d3e0c65
msys2:
  path: C:\msys64
  title: MSYS2 64bit
  version: '20190524'
cc: x86_64-w64-mingw32-gcc (Rev2, Built by MSYS2 project) 9.2.0
os: Microsoft Windows [版本 10.0.18362.535]
Rails 6.0.2.1

補充:我後來又用了bundle install,但還是啟動不了

C:\Users\admin\Desktop\line chat bot\noobcow>dir /w
 磁碟區 C 中的磁碟沒有標籤。
 磁碟區序號:  76E8-6435

 C:\Users\admin\Desktop\line chat bot\noobcow 的目錄

[.]             [..]            .gitignore      .ruby-version   config.ru       Gemfile         Gemfile.lock
Rakefile        README.md
               7 個檔案           8,254 位元組
               2 個目錄  94,492,856,320 位元組可用

C:\Users\admin\Desktop\line chat bot\noobcow>
C:\Users\admin\Desktop\line chat bot\noobcow>rails s
Usage:
  rails new APP_PATH [options]

Options:
      [--skip-namespace], [--no-skip-namespace]              # Skip namespace (affects only isolated applications)
  -r, [--ruby=PATH]                                          # Path to the Ruby binary of your choice
                                                             # Default: C:/Ruby26-x64/bin/ruby.exe
  -m, [--template=TEMPLATE]                                  # Path to some application template (can be a filesystem path or URL)
  -d, [--database=DATABASE]                                  # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                             # Default: sqlite3
      [--skip-gemfile], [--no-skip-gemfile]                  # Don't create a Gemfile
  -G, [--skip-git], [--no-skip-git]                          # Skip .gitignore file
      [--skip-keeps], [--no-skip-keeps]                      # Skip source control .keep files
  -M, [--skip-action-mailer], [--no-skip-action-mailer]      # Skip Action Mailer files
      [--skip-action-mailbox], [--no-skip-action-mailbox]    # Skip Action Mailbox gem
      [--skip-action-text], [--no-skip-action-text]          # Skip Action Text gem
  -O, [--skip-active-record], [--no-skip-active-record]      # Skip Active Record files
      [--skip-active-storage], [--no-skip-active-storage]    # Skip Active Storage files
  -P, [--skip-puma], [--no-skip-puma]                        # Skip Puma related files
  -C, [--skip-action-cable], [--no-skip-action-cable]        # Skip Action Cable files
  -S, [--skip-sprockets], [--no-skip-sprockets]              # Skip Sprockets files
      [--skip-spring], [--no-skip-spring]                    # Don't install Spring application preloader
      [--skip-listen], [--no-skip-listen]                    # Don't generate configuration that depends on the listen gem
  -J, [--skip-javascript], [--no-skip-javascript]            # Skip JavaScript files
      [--skip-turbolinks], [--no-skip-turbolinks]            # Skip turbolinks gem
  -T, [--skip-test], [--no-skip-test]                        # Skip test files
      [--skip-system-test], [--no-skip-system-test]          # Skip system test files
      [--skip-bootsnap], [--no-skip-bootsnap]                # Skip bootsnap gem
      [--dev], [--no-dev]                                    # Setup the application with Gemfile pointing to your Rails checkout
      [--edge], [--no-edge]                                  # Setup the application with Gemfile pointing to Rails repository
      [--rc=RC]                                              # Path to file containing extra configuration options for rails command
      [--no-rc], [--no-no-rc]                                # Skip loading of extra configuration options from .railsrc file
      [--api], [--no-api]                                    # Preconfigure smaller stack for API only apps
  -B, [--skip-bundle], [--no-skip-bundle]                    # Don't run bundle install
  --webpacker, [--webpack=WEBPACK]                           # Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus)
      [--skip-webpack-install], [--no-skip-webpack-install]  # Don't run Webpack install

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Rails options:
  -h, [--help], [--no-help]        # Show this help message and quit
  -v, [--version], [--no-version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.

C:\Users\admin\Desktop\line chat bot\noobcow>
看更多先前的回應...收起先前的回應...

不確定有沒有影響但你試試看把路徑上的空白先刪掉

cow03haha iT邦新手 5 級 ‧ 2019-12-20 16:22:38 檢舉

這樣嗎?

C:\Users\admin\Desktop\chatbot>rails new noobcow
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."

C:\Users\admin\Desktop\chatbot>
k827913k iT邦新手 5 級 ‧ 2019-12-23 21:06:53 檢舉

請問有解決嗎?
遇到一樣的問題 QQ

看不太出來問題在哪呢QQ

cow03haha iT邦新手 5 級 ‧ 2019-12-24 13:34:14 檢舉

郭佳甯
k827913k
今天再打一次可以了,我猜可能新版本剛出不穩定?

C:\Users\admin\Desktop\chatbot\noobcow>dir /w
 磁碟區 C 中的磁碟沒有標籤。
 磁碟區序號:  76E8-6435

 C:\Users\admin\Desktop\chatbot\noobcow 的目錄

[.]             [..]            .gitignore      .ruby-version   [app]           [bin]           [config]
config.ru       [db]            Gemfile         Gemfile.lock    [lib]           [log]           package.json
[public]        Rakefile        README.md       [storage]       [test]          [tmp]           [vendor]
               8 個檔案           8,686 位元組
              13 個目錄  93,016,797,184 位元組可用
0
zu1992
iT邦見習生 ‧ 2019-12-25 12:09:06

https://imgur.com/gallery/rVdBX1N
請問我輸入rails new pp
然後只有出現這樣一小段而已⋯⋯
試了很多次也改過資料夾名稱還是一樣

看更多先前的回應...收起先前的回應...
D:\只要有心,人人都可以做>rails new ironman
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."

我也是只出現了這些

QQ

剛剛測試了安裝ruby 2.3 版 跟 ruby 2.6.5 版
ruby 2.6.5版並不會跟著 ruby 安裝 git
所以才會發生執行到 run git init from "." 就停止的情形

解法有兩種一種是加上 --skip-git
rails new <projectName> --skip-git
另一種是安裝 git
Git 安裝教學

最簡單的解法就是第一種,不過如果想學 git 可以參考看看如何安裝
然後會遇到這個問題的大大是不是都沒有仔細看版大教學 不安裝2.4版XD

原來是醬 感謝回饋

mon60819 iT邦新手 5 級 ‧ 2020-02-16 19:53:54 檢舉

我也發生一樣的問題,
原先是跟著安裝2.4版的,
但是安裝2.4後要安裝rails就跳出說ruby要2.5版,
所以才又重新安裝了2.5版

0
mon60819
iT邦新手 5 級 ‧ 2020-02-16 19:50:06

你好,在rails new的地方輸入完卻沒有自己安裝像文章中那麼多的檔案
就只有出現短短這些,不知道是哪裡出了問題,謝謝

(Ruby是安裝2.5.7-1-x64版本)

mon60819 iT邦新手 5 級 ‧ 2020-02-16 19:52:37 檢舉

剛好看到上面有類似的留言了,找到解決問題了,謝謝

0
g11145590
iT邦新手 5 級 ‧ 2020-03-06 14:36:37

https://imgur.com/Xm0GZNp

有試過版大提供的方法:
將Gemfile中的gem 'sqlite3'改為gem 'sqlite3', '1.3.13',然後回到專案資料夾輸入bundle install
查詢網路後也試過改成gem 'sqlite3', '<1.4.0'

但最後還是出現上圖錯誤,
不知道是不是sqlite3的問題?

我的版本是2.5.7-1
謝謝!

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

應該是 ruby 版本的問題

g11145590 iT邦新手 5 級 ‧ 2020-03-06 16:58:07 檢舉

但因為跟上面留言的狀況一樣,
我安裝2.4後要安裝rails就跳出說ruby要2.5版,
所以只好重新安裝2.5版,
不知道這有沒有解?謝謝!

隨著時間前進我的文章也過時了嗎 Q_Q

g11145590 iT邦新手 5 級 ‧ 2020-03-09 11:13:33 檢舉

不好意思因為我是新手,不曉得有沒有其他辦法跨過這個坎呢QQ

try to reinstall your sqlite3 with below method

gem uninstall sqlite3 --all
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem inst sqlite3 --platform ruby

reference

微笑 iT邦新手 1 級 ‧ 2020-04-25 02:05:20 檢舉

看到樓主的回文才注意到
初音主題也是好懷念的東西啊wwwww

因為大部份的問題都出在版本上,ruby堅持裝2.4就好
安裝rails時使用gem install rails -v 4.2.8
(版大使用的5.1.4不支援ruby2.4了qq..)

然後Gemfile裡面的gem 'sqlite3', '1.3.13'一樣要改

key入bundle install再rails server就好了喔~

/images/emoticon/emoticon12.gif

我用了 微笑大大的方式還是沒用是我哪裡出錯了嗎QAQ

0
微笑
iT邦新手 1 級 ‧ 2020-04-25 01:46:26

嗨嗨,雖然留言沒有全部看完,如果在上一篇,因為各種原因沒安裝ruby2.4,導致在本篇產生錯誤,這邊提供一個解

在gem install rails 後面加上 -v 4.2.8,應該就可以正常安裝,後續操作也就正常了^^

/images/emoticon/emoticon12.gif

請問我照這個方式還不行怎麼辦呢QAQ

0
weiwei1007
iT邦新手 5 級 ‧ 2020-07-05 23:07:46

版主您好
我安裝rails時有使用gem install rails -v 4.2.8
然後Gemfile裡面的gem 'sqlite3', '1.3.13'也有改
bundle install再rails server一樣出了問題
唯一不同的是我安裝了2.6版本,而非2.4
因為版本必須 >=2.5
但我有使用
gem uninstall sqlite3 --all
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem inst sqlite3 --platform ruby
依然導致以下狀況
https://ithelp.ithome.com.tw/upload/images/20200705/20128399BbS9Yld5Fd.png
想請問這種問題該如何解決,麻煩版主了!

0
一條龍
iT邦新手 5 級 ‧ 2020-11-20 14:03:30

https://imgur.com/a/B2pcZPN
求問大大,我在執行rails new ironman時他最後叫我載yarn這東西,請問是要載入才能成功嗎?還是我有哪個環節漏掉了?

你使用的 rails 版本是 6 所以環境跟我文章上的有些許差異 需要多安裝 yarn

0
bean
iT邦新手 5 級 ‧ 2021-05-13 03:10:55

大大您好,在進行rails new ironman時出現了下面的畫面
https://ithelp.ithome.com.tw/upload/images/20210513/20137449oIRLmPzpso.jpg

之後在進行rails server的時候又出現了以下的畫面,請問該如何解決呢?謝謝大大
https://ithelp.ithome.com.tw/upload/images/20210513/20137449QgdIA7v5LZ.jpg
我用的版本是Ruby+Devkit 2.7.3-1 (x64)

0
mashiro0913
iT邦新手 5 級 ‧ 2021-07-31 19:08:40

請問有大大知道如何修改嗎qaq
已經改成1.3.13了但還是出現這樣....https://ithelp.ithome.com.tw/upload/images/20210731/20140015v9ry6p85vH.png

終於修好了只要把ironman的專案資料夾刪掉在cmd輸入 rails new ironman --skip-git再 bundle install最後再 rails server就完成了!花了好久的時間.....

使用的是ruby+devkit2.6.8-1(x64)
然後rails 5.2.6版本

0
mashiro0913
iT邦新手 5 級 ‧ 2021-07-31 23:38:37

有人可以教我怎麼處理這個狀況嗎QAQ
就算寫了1.3.13也是一直沒辦法用https://ithelp.ithome.com.tw/upload/images/20210731/20140015gLG9PlQgoO.png

0
1092B0007
iT邦新手 3 級 ‧ 2021-11-17 16:25:09

您好,我照您的教學輸入rails server
但卻出現這樣的訊息
請問我是哪裡做錯了
https://ithelp.ithome.com.tw/upload/images/20211117/20136759SjYljWgQ5v.png
謝謝

1092B0007 iT邦新手 3 級 ‧ 2021-11-19 08:46:54 檢舉

請問是代表執行時間過久嗎?

1092B0007 iT邦新手 3 級 ‧ 2021-11-19 08:47:36 檢舉

我照的那篇文章內容做
但是錯誤訊息卻變成這樣
https://ithelp.ithome.com.tw/upload/images/20211119/201367597gMshQBzlr.png
這是什麼意思?

我要留言

立即登入留言