Sinatraの環境構築
解決したいこと
Sinatraの環境構築に1週間ほど苦戦、、、らちが明かず何とかお助けいただきたく投稿しますTT
※勉強を始めて1か月ほどです。
例)
スクールの課題でSinatraの環境を構築しています。
過去2回できたのですが、立ち上げるたびに、ほかのコードを打つたびに環境が壊れ、ついに打つ手なしの状況です。(スクールでも質問を数日繰り返していますが、今回は解決に至らず)
どうか玄人の皆様解決方法を教えて下さい。
発生している問題・エラー
web-1 | /app/app.rb:1:in `<top (required)>': undefined method `get' for main:Object
ターミナル全文
Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Wed Feb 19 06:09:52 JST 2025
System load: 3.15 Processes: 74
Usage of /: 0.4% of 1006.85GB Users logged in: 0
Memory usage: 16% IPv4 address for eth0: 172.29.143.103
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
This message is shown once a day. To disable it please create the
/home/kenta/.hushlogin file.
kenta@sakamoto:~$ cd 75456_kenty-s_introduction_sinatra
kenta@sakamoto:~/75456_kenty-s_introduction_sinatra$ docker compose build
[+] Building 0/0
[+] Building 0/1Building 0.1s
[+] Building 6.1s (16/16) FINISHED docker:default
=> [web internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 374B 0.0s
=> [web] resolve image config for docker-image://docker.io/docker/dockerfile:1 3.3s
=> [web auth] docker/dockerfile:pull token for registry-1.docker.io 0.0s
=> CACHED [web] docker-image://docker.io/docker/dockerfile:1@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e 0.0s
=> => resolve docker.io/docker/dockerfile:1@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e36d0f104d4d801e66 0.0s
=> [web internal] load metadata for docker.io/library/ruby:3.1.4 1.9s
=> [web auth] library/ruby:pull token for registry-1.docker.io 0.0s
=> [web internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [web internal] load build context 0.1s
=> => transferring context: 14.63kB 0.1s
=> [web 1/6] FROM docker.io/library/ruby:3.1.4@sha256:8ebc619f459ec62a7d0763f910e50787cc7999de3c09632536b22aaf87 0.0s
=> => resolve docker.io/library/ruby:3.1.4@sha256:8ebc619f459ec62a7d0763f910e50787cc7999de3c09632536b22aaf8725d3 0.0s
=> CACHED [web 2/6] RUN apt-get update -qq && apt-get install -y build-essential sqlite3 && apt-get clea 0.0s
=> CACHED [web 3/6] WORKDIR /app 0.0s
=> CACHED [web 4/6] COPY Gemfile* ./ 0.0s
=> CACHED [web 5/6] RUN gem install bundler && bundle install 0.0s
=> CACHED [web 6/6] COPY / . 0.0s
=> [web] exporting to image 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:4d20e2cdb57183c82de439ae7c0dc2306fbfebe7ec6ca3cd19436b94de79320e 0.0s
=> => exporting config sha256:d9fec578a94df367d04a7402c6ddbbba675e997b5e634c68b64599bea7ccfd89 0.0s
=> => exporting attestation manifest sha256:8fbe270dce5ce3aa9d65b2652927935a5d02b9587ff9780e3d0f532df6af2395 0.0s
=> => exporting manifest list sha256:4af1491708be9df7fc66ca20fa7d8587700db2f63f84e1f8fba4cc94e5eaa9f3 0.0s
=> => naming to docker.io/library/75456_kenty-s_introduction_sinatra-web:latest 0.0s
[+] Building 1/1 to docker.io/library/75456_kenty-s_introduction_sinatra-web:latest 0.0s
✔ Service web Built 6.8s
kenta@sakamoto:~/75456_kenty-s_introduction_sinatra$ docker compose up
[+] Running 1/1
✔ Container 75456_kenty-s_introduction_sinatra-web-1 Rec... 0.4s
Attaching to web-1
web-1 | [1] Puma starting in cluster mode...
web-1 | [1] * Puma version: 6.4.2 (ruby 3.1.4-p223) ("The Eagle of Durango")
web-1 | [1] * Min threads: 0
web-1 | [1] * Max threads: 5
web-1 | [1] * Environment: development
web-1 | [1] * Master PID: 1
web-1 | [1] * Workers: 3
web-1 | [1] * Restarts: (✔) hot (✖) phased
web-1 | [1] * Preloading application
web-1 | [1] ! Unable to load application: NoMethodError: undefined method `get' for main:Object
web-1 |
web-1 | get '/' do
web-1 | ^^^
web-1 | Did you mean? gets
web-1 | gem
web-1 | bundler: failed to load command: puma (/usr/local/bundle/bin/puma)
web-1 | /app/app.rb:1:in `<top (required)>': undefined method `get' for main:Object (NoMethodError)
web-1 |
web-1 | get '/' do
web-1 | ^^^
web-1 | Did you mean? gets
web-1 | gem
web-1 | from config.ru:1:in `require'
web-1 | from config.ru:1:in `block (2 levels) in <top (required)>'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:108:in `eval'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:108:in `new_from_string'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:97:in `load_file'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:67:in `parse_file'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/configuration.rb:368:in `load_rackup'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/configuration.rb:290:in `app'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/runner.rb:162:in `load_and_bind'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/cluster.rb:371:in `run'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/launcher.rb:194:in `run'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/cli.rb:75:in `run'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/bin/puma:10:in `<top (required)>'
web-1 | from /usr/local/bundle/bin/puma:25:in `load'
web-1 | from /usr/local/bundle/bin/puma:25:in `<top (required)>'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `load'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `kernel_load'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli/exec.rb:23:in `run'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli.rb:486:in `exec'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli.rb:31:in `dispatch'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli.rb:25:in `start'
web-1 | from /usr/local/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/libexec/bundle:48:in `block in <top (required)>'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/friendly_errors.rb:120:in `with_friendly_errors'
web-1 | from /usr/local/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/libexec/bundle:36:in `<top (required)>'
web-1 | from /usr/local/bundle/bin/bundle:25:in `load'
web-1 | from /usr/local/bundle/bin/bundle:25:in `<main>'
web-1 exited with code 1
kenta@sakamoto:~/75456_kenty-s_introduction_sinatra$ docker compose down
[+] Running 2/2r Desktop o View Config w Enable Watch
✔ Container 75456_kenty-s_introduction_sinatra-web-1 Rem... 0.0s
✔ Network 75456_kenty-s_introduction_sinatra_default Rem... 0.3s
kenta@sakamoto:~/75456_kenty-s_introduction_sinatra$ docker compose build --no-cache
[+] Building 0/0
[+] Building 0/1Building 0.1s
[+] Building 26.3s (14/14) FINISHED docker:default
=> [web internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 374B 0.0s
=> [web] resolve image config for docker-image://docker.io/docker/dockerfile:1 1.0s
=> CACHED [web] docker-image://docker.io/docker/dockerfile:1@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e 0.0s
=> => resolve docker.io/docker/dockerfile:1@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e36d0f104d4d801e66 0.0s
=> [web internal] load metadata for docker.io/library/ruby:3.1.4 0.9s
=> [web internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [web 1/6] FROM docker.io/library/ruby:3.1.4@sha256:8ebc619f459ec62a7d0763f910e50787cc7999de3c09632536b 0.0s
=> => resolve docker.io/library/ruby:3.1.4@sha256:8ebc619f459ec62a7d0763f910e50787cc7999de3c09632536b22aaf8725d3 0.0s
=> [web internal] load build context 0.0s
=> => transferring context: 14.63kB 0.0s
=> [web 2/6] RUN apt-get update -qq && apt-get install -y build-essential sqlite3 && apt-get clean && 5.8s
=> [web 3/6] WORKDIR /app 0.0s
=> [web 4/6] COPY Gemfile* ./ 0.0s
=> [web 5/6] RUN gem install bundler && bundle install 14.2s
=> [web 6/6] COPY / . 0.2s
=> [web] exporting to image 3.7s
=> => exporting layers 3.0s
=> => exporting manifest sha256:f5250301104a790583b3df39008bfdfd93b804948cb6b0dbb746831bad294008 0.0s
=> => exporting config sha256:4705d0dd89fef67de6be3ee4aae42847ab41cb654e16efe283528c7c75af0420 0.0s
=> => exporting attestation manifest sha256:1c2856665edf0472273c196e7572bd4f08ef5d54ccb3ead006a604c7ebee7d29 0.0s
=> => exporting manifest list sha256:897b508594fbb9edce69cb5833582ed5f99900a6a4d4d567b83b997e644d54f2 0.0s
=> => naming to docker.io/library/75456_kenty-s_introduction_sinatra-web:latest 0.0s
[+] Building 1/1 to docker.io/library/75456_kenty-s_introduction_sinatra-web:latest 0.6s
✔ Service web Built 26.5s
kenta@sakamoto:~/75456_kenty-s_introduction_sinatra$ docker compose up
[+] Running 2/2
✔ Network 75456_kenty-s_introduction_sinatra_default Cre... 0.0s
✔ Container 75456_kenty-s_introduction_sinatra-web-1 Cre... 0.5s
Attaching to web-1
web-1 | [1] Puma starting in cluster mode...
web-1 | [1] * Puma version: 6.4.2 (ruby 3.1.4-p223) ("The Eagle of Durango")
web-1 | [1] * Min threads: 0
web-1 | [1] * Max threads: 5
web-1 | [1] * Environment: development
web-1 | [1] * Master PID: 1
web-1 | [1] * Workers: 3
web-1 | [1] * Restarts: (✔) hot (✖) phased
web-1 | [1] * Preloading application
web-1 | bundler: failed to load command: puma (/usr/local/bundle/bin/puma)
web-1 | [1] ! Unable to load application: NoMethodError: undefined method `get' for main:Object
web-1 |
web-1 | get '/' do
web-1 | ^^^
web-1 | Did you mean? gets
web-1 | gem
web-1 | /app/app.rb:1:in `<top (required)>': undefined method `get' for main:Object (NoMethodError)
web-1 |
web-1 | get '/' do
web-1 | ^^^
web-1 | Did you mean? gets
web-1 | gem
web-1 | from config.ru:1:in `require'
web-1 | from config.ru:1:in `block (2 levels) in <top (required)>'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:108:in `eval'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:108:in `new_from_string'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:97:in `load_file'
web-1 | from /usr/local/bundle/gems/rack-3.1.3/lib/rack/builder.rb:67:in `parse_file'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/configuration.rb:368:in `load_rackup'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/configuration.rb:290:in `app'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/runner.rb:162:in `load_and_bind'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/cluster.rb:371:in `run'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/launcher.rb:194:in `run'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/lib/puma/cli.rb:75:in `run'
web-1 | from /usr/local/bundle/gems/puma-6.4.2/bin/puma:10:in `<top (required)>'
web-1 | from /usr/local/bundle/bin/puma:25:in `load'
web-1 | from /usr/local/bundle/bin/puma:25:in `<top (required)>'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `load'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `kernel_load'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli/exec.rb:23:in `run'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli.rb:486:in `exec'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli.rb:31:in `dispatch'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/cli.rb:25:in `start'
web-1 | from /usr/local/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/libexec/bundle:48:in `block in <top (required)>'
web-1 | from /usr/local/lib/ruby/3.1.0/bundler/friendly_errors.rb:120:in `with_friendly_errors'
web-1 | from /usr/local/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/libexec/bundle:36:in `<top (required)>'
web-1 | from /usr/local/bundle/bin/bundle:25:in `load'
web-1 | from /usr/local/bundle/bin/bundle:25:in `<main>'
web-1 exited with code 1
kenta@sakamoto:~/75456_kenty-s_introduction_sinatra$
v View in Docker Desktop o View Config w Enable Watch
VSCode の app.rb
# frozen_string_literal: true
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'
db = SQLite3::Database.new 'db/kakeibo.db'
enable :method_override
get '/' do
erb :index
end
自分で試したこと
● ターミナルでリセット
docker compose down
● app.rb.saveで誤りであろうコードを削除
【削除前】
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'
db = SQLite3::Database.new 'db/kakeibo.db'
enable :method_override
set :root, File.dirname(__FILE__)
set :views, Proc.new { File.join(root, 'views') }
get '/' do
erb :index
end
git checkout master
git branch
git pull origin master
git checkout -b 02_hello_world
git branch
require 'sinatra'
get '/hello' do
"Hello World"
end
【削除後】
require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'
db = SQLite3::Database.new 'db/kakeibo.db'
enable :method_override
get '/' do
erb :index
end
● VScodeの打ち直し