goo blog サービス終了のお知らせ 

職案人

求職・歴史・仏教などについて掲載するつもりだが、自分の思いつきが多いブログだよ。適当に付き合って下さい。

Ruby on Railsのインストール

2022年09月05日 | ruby 3.1.2
Ruby on Railsのインストール


【開発環境】
OS:Win11(64ビット)
Ruby 3.1.2

Ruby on Railsとは
Railsとは、プログラミング言語「Ruby」で書かれたWebアプリケーションフレームワークです。Railsは、あらゆる開発者がWebアプリケーション開発で必要となる作業やリソースを事前に想定することで、Webアプリケーションをより手軽に開発できるように設計されています。他の多くのWebアプリケーションフレームワークと比較して、アプリケーションを開発する際のコード量がより少なくて済むにもかかわらず、より多くの機能を実現できます。

■Ruby on railsのインストール方法
Rubyがインストールした状態でこコマンドプロンプトに、以下のコマンドを入力する

・コマンド
Microsoft Windows [Version 10.0.22000.856]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Owner>gem install rails
Fetching concurrent-ruby-1.1.10.gem
Fetching activesupport-7.0.3.1.gem
Fetching tzinfo-2.0.5.gem
Fetching thor-1.2.1.gem
Fetching i18n-1.12.0.gem
Fetching method_source-1.0.0.gem
Fetching zeitwerk-2.6.0.gem
Fetching nokogiri-1.13.8-x64-mingw-ucrt.gem
Fetching crass-1.0.6.gem
Fetching loofah-2.18.0.gem
Fetching rails-html-sanitizer-1.4.3.gem
Fetching rails-dom-testing-2.0.3.gem
Fetching rack-2.2.4.gem
Fetching rack-test-2.0.2.gem
Fetching erubi-1.11.0.gem
Fetching builder-3.2.4.gem
Fetching actionview-7.0.3.1.gem
Fetching actionpack-7.0.3.1.gem
Fetching railties-7.0.3.1.gem
Fetching mini_mime-1.1.2.gem
Fetching marcel-1.0.2.gem
Fetching activemodel-7.0.3.1.gem
Fetching activerecord-7.0.3.1.gem
Fetching globalid-1.0.0.gem
Fetching activejob-7.0.3.1.gem
Fetching activestorage-7.0.3.1.gem
Fetching actiontext-7.0.3.1.gem
Fetching mail-2.7.1.gem
Fetching actionmailer-7.0.3.1.gem
Fetching actionmailbox-7.0.3.1.gem
Fetching websocket-extensions-0.1.5.gem
Fetching websocket-driver-0.7.5.gem
Fetching rails-7.0.3.1.gem
Fetching nio4r-2.5.8.gem
Fetching actioncable-7.0.3.1.gem
Successfully installed zeitwerk-2.6.0
Successfully installed thor-1.2.1
Successfully installed method_source-1.0.0
Successfully installed concurrent-ruby-1.1.10
Successfully installed tzinfo-2.0.5
Successfully installed i18n-1.12.0
Successfully installed activesupport-7.0.3.1
Successfully installed nokogiri-1.13.8-x64-mingw-ucrt
Successfully installed crass-1.0.6
Successfully installed loofah-2.18.0
Successfully installed rails-html-sanitizer-1.4.3
Successfully installed rails-dom-testing-2.0.3
Successfully installed rack-2.2.4
Successfully installed rack-test-2.0.2
Successfully installed erubi-1.11.0
Successfully installed builder-3.2.4
Successfully installed actionview-7.0.3.1
Successfully installed actionpack-7.0.3.1
Successfully installed railties-7.0.3.1
Successfully installed mini_mime-1.1.2
Successfully installed marcel-1.0.2
Successfully installed activemodel-7.0.3.1
Successfully installed activerecord-7.0.3.1
Successfully installed globalid-1.0.0
Successfully installed activejob-7.0.3.1
Successfully installed activestorage-7.0.3.1
Successfully installed actiontext-7.0.3.1
Successfully installed mail-2.7.1
Successfully installed actionmailer-7.0.3.1
Successfully installed actionmailbox-7.0.3.1
Successfully installed websocket-extensions-0.1.5
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

current directory: D:/pg/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/\p\g/Ruby31-x64/bin/ruby.exe -I D:/\p\g/Ruby31-x64/lib/ruby/3.1.0 -r ./siteconf20220822-29748-kuma82.rb extconf.rb
creating Makefile

current directory: D:/pg/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean

current directory: D:/pg/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
generating websocket_mask-x64-mingw-ucrt.def
compiling websocket_mask.c
linking shared-object websocket_mask.so
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../lib/dllcrt2.o: Illegal byte sequence
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/crtbegin.o: Illegal byte sequence
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lx64-ucrt-ruby310: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lshell32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lws2_32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liphlpapi: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -limagehlp: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lshlwapi: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lbcrypt: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lssp_nonshared: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lssp: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmingw32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmoldname: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmingwex: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmsvcrt: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lkernel32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpthread: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ladvapi32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lshell32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -luser32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lkernel32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmingw32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_s: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmoldname: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmingwex: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmsvcrt: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lkernel32: No such file or directory
D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find D:/����/Ruby31-x64/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/crtend.o: Illegal byte sequence
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:263: websocket_mask.so] エラー 1

make failed, exit code 2

Gem files will remain installed in D:/pg/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/pg/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

C:\Users\Owner>rails -v
Rails 7.0.3.1

以上
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

簡単なアプリ

2022年08月21日 | ruby 3.1.2
簡単なアプリ


【開発環境】
OS:Win11(64ビット)
Ruby 3.1.2

■ファイルを読み書きするアプリを作ってみる
「file1.rb」フアイルにコードを書いてみる。
file_path = 'sample.txt'

#テキストファイルに書き込む
open(file_path,'w') do |f|
f.puts('Hello,World!')
end

#テキストファイルから読み込む
open(file_path,'r') do |f|
p f.read
end

・コマンド実行
Microsoft Windows [Version 10.0.22000.856]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Owner>ruby D:\pg\Ruby31-x64\サンプルプログラム\file1.rb
"Hello,World!\n"

C:\Users\Owner>

・「sample.txt」を見てみる
「Hello,World!」が書き込めれている

データを追加する
「file2.rb」フアイルにコードを書いてみる。
file_path = 'sample.txt'

#テキストファイルに書き込む
open(file_path,'a') do |f|
f.puts('Hello,Hello,World!')
end

#テキストファイルから読み込む
open(file_path,'r') do |f|
p f.read
end

・コマンド実行
C:\Users\Owner>ruby D:\pg\Ruby31-x64\サンプルプログラム\file2.rb
"Hello,World!\nHello,Hello,World!\n"

C:\Users\Owner>

・「sample.txt」を見てみる
Hello,World!
Hello,Hello,World!
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

標準ライブラリ

2022年08月19日 | ruby 3.1.2
標準ライブラリ


【開発環境】
OS:Win11(64ビット)
Ruby 3.1.2

【dateモジュール】
「library1.rb」ファイルにコードを書き込む

require 'date'←

today = Date.today

p today
p today.year

day_of_the_weeks = %w(日 月 火 水 木 金 土)
day_of_the_week = day_of_the_weeks[today.wday]

p today.strftime('%Y年%m月%d日') + day_of_the_week + '曜日'

C:\Users\Owner>ruby D:\pg\Ruby31-x64\サンプルプログラム\library1.rb
#<Date: 2022-08-19 ((2459811j,0s,0n),+0s,2299161j)>
2022
"2022年08月19日金曜日"

C:\Users\Owner>
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

モジュール

2022年08月18日 | ruby 3.1.2
モジュール


【開発環境】
OS:Win11(64ビット)
Ruby 3.1.2

1.モジュールとは
モジュール→処理(メソッド)をひとまとまりにする仕組み。クラスと違って、インスタンスを生成できない

2.使用例--include
「module1.rb」ファイルのコードを書く
module SampleModule
def Sample_mothod
p 'call sample_method.'
end
end

class SampleClass
include SampleModule
end

instance = SampleClass.new ※インスタンを生成する
instance.Sample_mothod


コマンドを実行する
Microsoft Windows [Version 10.0.22000.856]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Owner>ruby D:\pg\Ruby31-x64\サンプルプログラム\module1.rb
"call sample_method."

C:\Users\Owner>

3.使用例2--extend
「module2.rb」ファイルのコードを書く
module SampleModule
def Sample_mothod
p 'call sample_method.'
end
end

class SampleClass
extend SampleModule
end

SampleClass.Sample_mothod

コマンドを実行する
C:\Users\Owner>ruby D:\pg\Ruby31-x64\サンプルプログラム\module2.rb
"call sample_method."
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

例外--raise

2022年08月17日 | ruby 3.1.2
例外を発生させる


【開発環境】
OS:Win11(64ビット)
Ruby 3.1.2

・例外を発生させるraise命令
例外を意図的に発生させるには、raise命令を使う

構成文
1.raise'エラーメッセージ'
2.raise 例外の種類、'エラーメッセージ'

・「raise.rb」ファイルにコードを書く
begin
# TypeError例外を発生
raise TypeError,'original error'
rescue => e
p e.message
# 例外処理後に例外を再発生
raise
end

・コマンドの実行
Microsoft Windows [Version 10.0.22000.856]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Owner>ruby D:\pg\Ruby31-x64\サンプルプログラム\raise.rb
"original error"
D:/pg/Ruby31-x64/サンプルプログラム/raise.rb:3:in `
': original error (TypeError)

C:\Users\Owner>
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする