Ruby on Rails入門メモ
Ruby on Railsをさわってて、躓いた点をメモ。
環境
Windows8 64bit
Rubyのインストールディレクトリ:C:\Ruby200-x64
DevKitのインストールディレクトリ:C:\Ruby200-x64\devkit
Railsプロジェクトを作成して、サーバ起動時にエラー
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.2/lib/tzinfo/data_source.rb:182:in `rescue in create_default_data_source': No source of timezone data could be found. (TZInfo::DataSourceNotFound)
対処
Gemfileを開いて以下を修正
gem 'tzinfo-data', platforms: [:mingw, :mswin]
↓
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
修正後、bundle updateを実行
参考URL
https://github.com/tzinfo/tzinfo/wiki/Resolving-TZInfo::DataSourceNotFound-Errors
scaffoldでエラー
rails generate scaffold User実行後、http://localhost:3000/usersにアクセスすると、
ExecJS::RuntimeError in Users#index
対処
runtimes.rbの以下を修正
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo //U",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
)
↓
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-8' # CScript with //U returns UTF-16LE
)
runtimes.rbは、execjsのインストールフォルダのlib/execjs
インストールフォルダはbundle show execjsで確認
参考URL
http://stackoverflow.com/questions/13530042/execjsruntimeerror-in-usersindex-ror
rails db実行で、エラー
Couldn't find database client: sqlite3, sqlite3.exe. Check your $PATH and try again.
対処
※SQLite3のx64版は提供されていないので、自分の環境でビルドしないといけない。
ビルドツールはC:\Ruby200-x64\devkit\mingw\bin\x86_64-w64-mingw32-gcc.exe
ダウンロードサイトhttp://www.sqlite.org/download.htmlからsqlite-amalgamation-3080500.zipをダウンロードし、解凍する。
2.SQLite3.dllをビルドする。
1で解凍したフォルダに移動し、以下を実行
x86_64-w64-mingw32-gcc -O2 -shared -o sqlite3.dll -Wl--out-implib=libsqlite3.dll.a sqlite3.c
SQLite3.dllが生成される。
3.SQLite3.exeをビルドする。
1で解凍したフォルダに移動し、以下を実行
x86_64-w64-mingw32-gcc -O2 -o sqlite3.exe shell.c libsqlite3.dll.a
SQLite3.exeが生成される。
4. SQLite3.dll、SQLite3.exeをインストール
2、3で生成されたSQLite3.dll、SQLite3.exeをC:\Ruby200-x64\binにコピーする。
参考URL
http://niche-treasurer.mo-blog.jp/blog/2014/04/ruby_on_rails_6.html