jpmobileのインストール

インストール

Jpmobileをローカルインストール - 眼鏡手記 : QiQを参照しましたが、Windows環境でも単にこうすれば大丈夫のようです。

詳細は下記を参照。

[C:\Ruby]
$ gem install jpmobile
Successfully installed jpmobile-0.0.6
1 gem installed
Installing ri documentation for jpmobile-0.0.6...
Installing RDoc documentation for jpmobile-0.0.6...

[C:\Ruby]
$

設定

RAILS_ROOT/config/environment.rbを下記のように変更します。

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install
  # config.gem "bj"
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  # config.gem "sqlite3-ruby", :lib => "sqlite3"
  # config.gem "aws-s3", :lib => "aws/s3"

  # Use Jpmobile.
  # see, http://github.com/darashi/jpmobile/tree/master
  config.gem "jpmobile"

【以下略】

インストールの確認

こんな感じで↓

[C:\pleiades-e3.5\workspace\test]
$ ruby script\console
Loading development environment (Rails 2.3.3)
>> Jpmobile::VERSION::STRING
=> "0.0.6"
>>

概要

社内勉強会を立ち上げる - part 3 : Jpmobileを使ってみる: Kwappa開発室を見てください。

#私はまだお勉強中。orz

scaffoldカスタマイズのはじめの一歩

まずは、概要をsymfony と Railsの狭間: [Rails 2.0.2]scaffoldをカスタマイズ?でお勉強。

http://opqr.jp/2007/10/xhtml.htmlを参考に、C:\src\test\lib\generators\scaffold\templates\layout.html.erbを下記のように変更。こっちも参考にしました。
#C:\srcで"rails test"したと思ってください。

<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head>
  <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=Shift_JIS" />
  <meta name="description" content="" />
  <meta name="keywords" content="" />
  <meta name="robots" content="index,follow" />
  <title><%= controller_class_name %>: <%%= controller.action_name %></title>
  <%%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%%= flash[:notice] %></p>

<%%= yield %>

</body>
</html>

Rails 2.1 で Shift-JIS - 涅ir槃naのmoriqさんのコメントを参考にC:\src\test\config\environment.rbを下記のように変更。

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install
  # config.gem "bj"
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  # config.gem "sqlite3-ruby", :lib => "sqlite3"
  # config.gem "aws-s3", :lib => "aws/s3"

  # Only load the plugins named here, in the order given (default is alphabetical).
  # :all can be used as a placeholder for all plugins not explicitly named
  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,
  # you must remove the Active Record framework.
  # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  # Run "rake -D time" for a list of tasks for finding time zone names.
  config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
  # config.i18n.default_locale = :de

  # Set output encodeing to Shift-JIS.
  # see, http://d.hatena.ne.jp/babie/20080717/1216288094
  config.action_controller.default_charset = 'Shift_JIS'
end


これで、Shift-JISになったみたいです。

Instant Rails-2.0で"ruby script\generate scaffold"してもフィールドなしの画面しか出来ない

ここここで調べて別にInstant Rails-2.0のせいではないと判ったのですが、Rails 2.0のscaffoldの振る舞いが変わったようでブラウザ画面で表示・編集したいフィールドは明示的に指定しないといけなくなったようです。

WEB+DB PRESS Vol.32の連載Ruby on Rails Wayの第1回の例だとこうなります。

C:\Tools\InstantRails-2.0\rails_apps\demo>ruby script\generate scaffold Recipe title:string description:string written_on:date instructions:text
      exists  app/models/
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/recipes
      exists  app/views/layouts/
      exists  test/functional/
      exists  test/unit/
      create  app/views/recipes/index.html.erb
      create  app/views/recipes/show.html.erb
      create  app/views/recipes/new.html.erb
      create  app/views/recipes/edit.html.erb
      create  app/views/layouts/recipes.html.erb
      create  public/stylesheets/scaffold.css
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
      create    app/models/recipe.rb
      create    test/unit/recipe_test.rb
      create    test/fixtures/recipes.yml
      exists    db/migrate
      create    db/migrate/002_create_recipes.rb
      create  app/controllers/recipes_controller.rb
      create  test/functional/recipes_controller_test.rb
      create  app/helpers/recipes_helper.rb
       route  map.resources :recipes

C:\Tools\InstantRails-2.0\rails_apps\demo>

また、migrationファイルの書式も変わったようです。この例では下記のようになります。

class CreateRecipe < ActiveRecord::Migration
  def self.up
    create_table :recipes do |t|
      t.string :title, :default => ''
      t.string :description
      t.date :written_on
      t.text :instructions
    end
  end

  def self.down
    drop_table :recipes
  end
end

Instant Rails-2.0で"rake migrate"に失敗する

ぐぐってこちらで知りましたが、Railsのバージョンが上がったせいか、"rake migrate"から"rake db:migrate"に変わったようです。

C:\Tools\InstantRails-2.0\rails_apps\demo\db\migrate>rake migrate
(in C:/Tools/InstantRails-2.0/rails_apps/demo)
rake aborted!
Don't know how to build task 'migrate'

(See full trace by running task with --trace)

C:\Tools\InstantRails-2.0\rails_apps\demo\db\migrate>rake db:migrate
(in C:/Tools/InstantRails-2.0/rails_apps/demo)
== 1 CreateRecipe: migrating ==================================================
-- create_table(:recipes)
   -> 0.1090s
== 1 CreateRecipe: migrated (0.1090s) =========================================


C:\Tools\InstantRails-2.0\rails_apps\demo\db\migrate>

Instant Rails-2.0のインストール

InstantRails-2.0-win.zipをここからダウンロードして、私の場合はC:\Tools\InstantRails-2.0配下に展開しました。

WEB+DB PRESS Vol.32の連載Ruby on Rails Wayの第1回を見ながら、サンプルアプリケーションのtypoを起動しようとしたら、こんなエラーが!

プロシージャ エントリ ポイント mysql_stmt_row_tell がダイナミック リンク ライブラリ LIBMYSQL.dll から見つかりませんでした。

ぐぐると、ここに解決策が書いてありました。C:\Tools\InstantRails-2.0\mysql\binにサーチパスを通しても解決しそうですが、ディレクトリごとコピーして環境を引越し可能にしたいので、前に習えでlibmySQL.dllをC:\Tools\InstantRails-2.0\ruby\binにコピーしておきます。やはり、サーチパスを通しました。mysqlコマンドを使うので。

思うに、InstantRails.exeが起動直後にmysql\binとかをサーチパスに付け加えるようにputenv()すれば良いのでは?

#簡単そうな修正なので、私でも出来そうだけど。