12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

英単語帳アプリ Reijiroの導入

Last updated at Posted at 2012-08-19

Reijiroは西村賢さんが作成された、英辞郎を使った単語帳アプリです。
このソフトウェアは記録を定着しやすくするSRS(Spaced Repetitio System)を組み込み、効率良く英語を学習することができます。

英辞郎 第六版

プロジェクトページ

ソースコード

解説記事

英辞郎によるSRS単語学習アプリ「Reijiro」を公開しました

実行環境

OSX 10.7.4

RVMインストール前

$ ruby -v
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]

RVMインストール後

$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.2]

外部公開サイトには筆者の都合により、CentOSを使っています。

$ cat /etc/redhat-release 
CentOS release 6.2 (Final)
$ ruby -v
ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-linux]

Homebrewのインストール

gitとqtのインストールのために、brewをインストールします。
すでにHomebrewがインストールされている場合は不要です。

$ ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)

Gitのインストール

githubからダウンロードするために、gitをインストールします。

$ brew install git

QTをインストール

Reijiroをインストールするときに、必要なcapybara-webkitを使うため、QTをインストールします。

$ brew install qt

RVMのインストール

ReijiroはRuby1.9.2以上が必要なため、RVMを使って仮想環境を構築します。
執筆時点ではruby 1.9.3p194がデフォルトでインストールされます。
すでにRubyの1.9.2以上がインストールされている場合は不要です。

  $ https://get.rvm.io | bash -s stable --ruby
  $ . ~/.bashrc 

Reijiroのインストール

$ ~/
$ git clone https://github.com/knsmr/reijiro
$ cd reijiro
$ bundle install

英辞郎をインストールします。

$ mkdir -p ~/Documents/Eijiro6T
$ cd  ~/Documents/Eijiro6T

英辞郎に付属している、辞書データを解凍します。
CDドライブに英辞郎のCDROMを挿入した状態です。
解凍するには英辞郎第六版のP28の記載されている製品コードを入力します。


  $ unzip /Volumes/EIJIRO_VI/Eijiro6T/TXT.zip
  Archive:  /Volumes/EIJIRO_VI/Eijiro6T/TXT.zip
  [/Volumes/EIJIRO_VI/Eijiro6T/TXT.zip] EIJI-128.TXT password: 
    inflating: EIJI-128.TXT            
    inflating: REIJI128.TXT            
    inflating: RYAKU128.TXT            
    inflating: WAEI-128.TXT
  $ cd ~/reijiro

データベースの作成と辞書の登録をおこないます。
デフォルトで~/Documents/Eijiro6T以下にある辞書ファイルを読み込みます。

$ rake db:convert

サービスの起動

-dはデーモンモードで起動する。

$ sudo rails s -d

ウェブサイトへアクセス

http://localhost:3000/levels

トラブルシューティングその1

問題:
QTがインストールされていないため、capybara-webkitのインストールで失敗する。

環境:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.2]

現象:

  $ bundle install
  Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

          /Users/saicologic/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 

  Gem files will remain installed in /Users/saicologic/.rvm/gems/ruby-1.9.3-p194/gems/capybara-webkit-0.12.1 for inspection.
  Results logged to /Users/saicologic/.rvm/gems/ruby-1.9.3-p194/gems/capybara-webkit-0.12.1/./gem_make.out
  An error occured while installing capybara-webkit (0.12.1), and Bundler cannot continue.
  Make sure that `gem install capybara-webkit -v '0.12.1'` succeeds before bundling.
  MacBookAir:reijiro saicologic$ /Users/saicologic/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 

解決方法:QTをインストールする。
参考URL: Installing-Qt-and-compiling-capybara-webkit

OSXの場合:

  $ brew update
  $ brew install qt

CentOSの場合:

  $ sudo yum install qtwebkit-devel
  $ export QMAKE=/usr/bin/qmake-qt4

トラブルシューティングその2

問題:
Rails Server起動時に、Could not find a JavaScript runtimeのエラーが表示される。
Javascript Runtimeが見つからないためにおこります。Rubyの1.9.2でおこります。

環境:
ruby 1.9.2p318 (2012-02-14 revision 34678) [x86_64-linux]

現象:

$ rails s
	/usr/local/rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
$ vim ./Gemfile
gem 'execjs'
gem 'therubyracer'

Productionモードの設定

データベースをDevelopmentからProductionへコピーする。

$ cp -ip db/development.sqlite3  db/production.sqlite3

assetの設定

Rails3.1からJavascriptやCSSは一つのファイルにコンパイルするようになったため、assetsの設定をします。

assetsを有効にする。

$ ./config/application.rb
config.assets.enabled = true

assetsをprecompileする。

RAILS_ENV=production bundle exec rake assets:precompile

Nginxから静的ファイルを配信するため、sconfig.serve_static_assetsをtrueにします。また、assetsファイルを事前にコンパイルしたため、config.assets.compileをfalseにします。

$ ./config/environments/production.rb 
config.serve_static_assets = true
config.assets.compile = false

assetsが作成できたか確認をする。

$ ls public/assets/
application-3df715da825f42b6219a42bae97ff6c1.js        bootstrap.responsive
application-3df715da825f42b6219a42bae97ff6c1.js.gz     glyphicons-halflings-0e7ff93d8f48fe1f5f762e4312e78da7.png
application-d4827b74482022f3671b19a2f579096b.css       glyphicons-halflings-white-ef3d5b8d6a297804352b4a46fdb5466d.png
application-d4827b74482022f3671b19a2f579096b.css.gz    glyphicons-halflings-white.png
application.css                                        glyphicons-halflings.png
application.css.gz                                     manifest.yml
application.js                                         rails-be8732dac73d845ac5b142c8fb5f9fb0.png
application.js.gz                                      rails.png
bootstrap-2373e4a47a3cfb58667dd29e495ca2ae.responsive

Productionモードでサービスを起動する。

$ rails s -e production -d

外部サイトへの公開

公開する場合、英辞郎の著作権があるため、Basic認証をかけてアクセス制限をかける必要があります。

Nginxのインストール

ヴァーチャルホストの設定をするために、Nginxを設定します。
IPでアクセスする場合はNginxは不要です。

$ yum -y install nginx

NginxのVersionを確認する。

$ nginx -v
nginx version: nginx/1.0.15

upstreamの設定をする。

$ vi /etc/nginx/conf.d/default.conf
upstream reijiro {
	server 127.0.0.1:3000;
}

serverの設定をする。

$ vi /etc/nginx/conf.d/virtual.conf

example.comには、所有しているドメインを入力する。

server {
    listen       80; 
    server_name  reijiro.example.com;
    access_log   /var/log/httpd/example.com.access.log;
    error_log    /var/log/httpd/example.error.log;
     
    location / {
      proxy_pass http://reijiro;
    }
}

DNSの設定

DNSにAレコードを設定します。

BASIC認証の設定

$ cd config/initializers
$ mv basic_authentication.sample basic_authentication.rb
$ vi basic_authentication.rb

basic_authentication.rbの9行目にユーザーとパスワードを設定する。

config.basic_auth = ['yourusername', 'yourpassword']

設定ファイルを確認する。

$ sudo service nginx configtest

Nginxの起動

$ sudo service nginx start
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

サービスに接続

http://[globalip]:3000/

もしくは、

http://reijiro.example.com
12
12
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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?