先日、TwitterのTL見てたら僕にぴったりのブログエントリがありました。

Rubyを始めたい方向けまとめ(2011年秋版)

 

初めてPadrinoの存在を知りましたが、結構メジャーみたいです。
さっそくチュートリアルを試してみます!

Padrino

最近これをテーマとした勉強会も開かれ、勢いがあります。

railsでは大きすぎるし、sinatraではちょっと足りない、そんなニーズに応えるものです。
管理画面が作りやすいのも特長ですね。

  DBが必要なので、MySQLをインストールします。

# yum install mysql-server
# yum install mysql-devel

 

続いて、mysqlアダプタとpadrinoをインストール。

# gem install mysql
# gem install padrino

 

プロジェクトを生成します。
オプションは色々ありますが、以下の様にしました。
詳しくはマニュアルを参照してください。

% padrino g project example_blog -a mysql -d activerecord -t rspec -s jquery -e haml scss -b
      create  
      create  .gitignore
      create  config.ru
      create  config/apps.rb
      create  config/boot.rb
      create  public/favicon.ico
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  tmp
      create  .components
      create  app
      create  app/app.rb
      create  app/controllers
      create  app/helpers
      create  app/views
      create  app/views/layouts
      create  Gemfile
    applying  activerecord (orm)...
       apply  orms/activerecord
      insert  Gemfile
      insert  Gemfile
      create  config/database.rb
    applying  rspec (test)...
       apply  tests/rspec
      insert  Gemfile
      insert  Gemfile
      create  spec/spec_helper.rb
      create  spec/spec.rake
    skipping  mock component...
    applying  jquery (script)...
       apply  scripts/jquery
      create  public/javascripts/jquery.js
      create  public/javascripts/jquery-ujs.js
      create  public/javascripts/application.js
    applying  haml (renderer)...
       apply  renderers/haml
      insert  Gemfile
    skipping  stylesheet component...
   identical  .components
Bundling application dependencies using bundler...
         run  bundle install from "."
Fetching source index for http://rubygems.org/
Enter your password to install the bundled RubyGems to your system: 
Using rake (0.9.2.2) 
Using multi_json (1.0.3) 
Using activesupport (3.1.1) 
Using builder (3.0.0) 
Using i18n (0.6.0) 
Using activemodel (3.1.1) 
Using arel (2.2.1) 
Using tzinfo (0.3.31) 
Using activerecord (3.1.1) 
Using bundler (1.0.21) 
Using diff-lcs (1.1.3) 
Using mime-types (1.17.2) 
Using grit (2.4.1) 
Using haml (3.1.3) 
Using rack (1.3.5) 
Using url_mount (0.2.1) 
Using http_router (0.10.2) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.3.0) 
Using mysql (2.8.1) 
Using rack-protection (1.1.4) 
Using tilt (1.3.3) 
Using sinatra (1.3.1) 
Using thor (0.14.6) 
Using padrino-core (0.10.5) 
Using padrino-helpers (0.10.5) 
Using padrino-admin (0.10.5) 
Using padrino-cache (0.10.5) 
Using padrino-gen (0.10.5) 
Using padrino-mailer (0.10.5) 
Using padrino (0.10.5) 
Using rack-test (0.6.1) 
Using rspec-core (2.7.1) 
Using rspec-expectations (2.7.0) 
Using rspec-mocks (2.7.0) 
Using rspec (2.7.0) 
Using sinatra-flash (0.3.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

=================================================================
example_blog is ready for development!
=================================================================
$ cd ./example_blog
=================================================================

 

次にDBの接続情報を自分の環境に書き換えます。

% cd example_blog
% vim config/database.rb

 

では、さっそく管理画面を作ってみましょう。

% padrino g admin
       force  .components
      create  admin
       exist  admin
      create  admin/controllers/base.rb
      create  admin/controllers/sessions.rb
      create  public/admin
      create  public/admin/stylesheets/base.css
      create  public/admin/stylesheets/themes/amro/style.css
      create  public/admin/stylesheets/themes/bec-green/style.css
      create  public/admin/stylesheets/themes/bec/style.css
      create  public/admin/stylesheets/themes/blue/style.css
      create  public/admin/stylesheets/themes/default/style.css
      create  public/admin/stylesheets/themes/djime-cerulean/style.css
      create  public/admin/stylesheets/themes/kathleene/style.css
      create  public/admin/stylesheets/themes/olive/style.css
      create  public/admin/stylesheets/themes/orange/style.css
      create  public/admin/stylesheets/themes/reidb-greenish/style.css
      create  public/admin/stylesheets/themes/ruby/style.css
      create  public/admin/stylesheets/themes/warehouse/style.css
      create  admin/app.rb
      append  config/apps.rb
       apply  orms/activerecord
       apply  tests/rspec
      create  models/account.rb
      create  spec/models/account_spec.rb
      create  db/migrate/001_create_accounts.rb
      create  admin/views/accounts
      create  admin/controllers/accounts.rb
      create  admin/views/accounts/_form.haml
      create  admin/views/accounts/edit.haml
      create  admin/views/accounts/index.haml
      create  admin/views/accounts/new.haml
      insert  admin/app.rb
       force  models/account.rb
      create  db/seeds.rb
       exist  admin/controllers
       exist  admin/views
      create  admin/views/base
      create  admin/views/layouts
      create  admin/views/sessions
      create  admin/views/base/_sidebar.haml
      create  admin/views/base/index.haml
      create  admin/views/layouts/application.haml
      create  admin/views/sessions/new.haml
      insert  admin/app.rb
      insert  Gemfile
        gsub  admin/views/accounts/_form.haml
        gsub  admin/controllers/accounts.rb

=================================================================
The admin panel has been mounted! Next, follow these steps:
=================================================================
  1) Run 'bundle install'
  2) Run 'padrino rake ar:migrate'
  3) Run 'padrino rake seed'
  4) Visit the admin panel in the browser at '/admin'
=================================================================

 

メッセージの支持に従って、bundle installなどを実行して、サーバを起動。

% bundle install
% padrino rake ar:migrate
% padrino rake seed
% padrino s

 

ブラウザでサイトにアクセスすると管理画面が表示されました。

今日はここまで。