LoginSignup
0
0

More than 1 year has passed since last update.

初学者が「rails new 〜」 で起きたエラー

Posted at

環境構築をし、ブラウザで「Hello World」を表示させようとしたときに起きた話

スペック

macOS Big Sur バージョン11.3.1
MacBook Air (M1, 2020)
を2021年5月に購入しました。それまではWindowsをずっと使っていました。

手順

●rails環境構築
1、Command Line Toolsをインストール
2,Homebrewをインストール(ver 3.1.12)
3,rbenvをインストール(ver 1.1.2)
4,Rubyをインストール(ver 3.0.1)
5,railsをインストール(ver 6.1.3.2)
6,yarnをインストール(ver 1.22.10)

●プロジェクト作成
1、railsでプロジェクト作成

% mkdir ruby_project
% cd ruby_project
% rails new hello_app

2、hello_appをvscodeで開く

3、「Hello World」実行

起きたエラー

% rails new hello_app
.
.
.
Argumenterror: method name must be a Symbol but Falseclass is given
.
.
.

訳: Argumenterror:メソッド名はSymbolである必要がありますが、Falseclassが指定されています

んー、よくわからない…
どこで指定されているのかもわからない…

とりあえずインストールしたものを上からバージョンを確認していったところ、
rubyのバージョンが古いものをインストールしている事が判明(最新のをインストールしたつもり…)

ruby 3.0.1 をインストールし、railsとyarnも一応再インストールすると
今度はなんの問題もなく、プロジェクト作成に成功

application_controller.rb
class ApplicationController < ActionController::Base
    def hello
        render html: "Hello World"
    end
end

routers.rb
Rails.application.routes.draw do
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
  root 'application#hello'
end

と変更し、rails sでサーバーを立ち上げ
スクリーンショット 2021-06-20 12.01.22.png

見事「Hello World」に成功!!!!

その他

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>
warning webpack-dev-server > sockjs > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning webpack-dev-server > webpack-log > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

プロジェクト作成が上手くいったものの、途中でこんなログが表示された。
gitやwebpackのことが書かれているので、こちらも調べて改善していきたい。

感想

M1Macに環境構築するのは初学者では躓いてしまう可能性があると言われている中購入したので
不安はありましたが、今の所なんとかやれているので、大丈夫そうです
これからもいろいろな壁にぶつかると思いますが、めげずに頑張りたいと思います。
Qiitaにもアウトプットしていき、同じようなところで躓いている初学者の方のためになったらいいなと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0