FreeBSD で ruby on rails
スポンサーリンク
FreeBSD De Ruby on Rails を試してみました。
portsから railsをインストールできます。
ためしに、ブックマークを作ってみるデモ。
アプリケーションの構築コマンド
色々ファイルが生成されました。
script/server でポート 3000 で http のサーバが動きます。
データベースを作成します。
テーブルを作成します。
コントローラはこんなカンジ。
サーバを起動します。
ポート3000で動作します。
http://localhost:3000/bm にアクセスすると Listing bms と表示されます。
http://localhost:3000/bm/new で新しいエントリが追加できます。
データベースにアカウントを作成
参考
http://wiki.rubyonrails.org/rails/pages/RailsOnFreeBSD
portsから railsをインストールできます。
cd /usr/ports/www/rubygem-rails sudo make install clean cd /usr/ports/databases/ruby-mysql/ sudo make install clean
ためしに、ブックマークを作ってみるデモ。
アプリケーションの構築コマンド
薫$ rails bm
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create components
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create script/process
create test/fixtures
create test/functional
create test/integration
create test/mocks/development
create test/mocks/test
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application.rb
create app/helpers/application_helper.rb
create test/test_helper.rb
create config/database.yml
create config/routes.rb
create public/.htaccess
create config/boot.rb
create config/environment.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/breakpointer
create script/console
create script/destroy
create script/generate
create script/performance/benchmarker
create script/performance/profiler
create script/process/reaper
create script/process/spawner
create script/process/inspector
create script/runner
create script/server
create script/plugin
create public/dispatch.rb
create public/dispatch.cgi
create public/dispatch.fcgi
create public/404.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
色々ファイルが生成されました。
薫$ cd bm 薫$ ls README app config doc log script tmp Rakefile components db lib public test vendor
script/server でポート 3000 で http のサーバが動きます。
% ./script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options
データベースを作成します。
薫$ mysqladmin -u root -p create bm_development Enter password:
テーブルを作成します。
薫$ ./script/generate migration bm
create db/migrate
create db/migrate/001_bm.rb
薫$ cat db/migrate/001_bm.rb
class Bm < ActiveRecord::Migration
def self.up
end
def self.down
end
end
薫$ vim db/migrate/001_bm.rb
薫$ cat db/migrate/001_bm.rb
[src]
class Bm < ActiveRecord::Migration
def self.up
create_table :bms do |table|
table.column :url, :string
table.column :title, :string
table.column :desc, :string
end
end
def self.down
end
end
薫$ rake migrate (in /home/kaworu/p/ruby/rails/bm) [src] == Bm: migrating ============================================================== -- create_table(:bms) -> 0.0074s == Bm: migrated (0.0081s) ===================================================== The rake task migrate has been deprecated, please use the replacement version db:migrateこれで、テーブルは作成完了です。
薫$ mysql -u root -p bm_development Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 733 to server version: 5.1.6-alpha-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> desc bms; +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | url | varchar(255) | YES | | NULL | | | title | varchar(255) | YES | | NULL | | | desc | varchar(255) | YES | | NULL | | +-------+--------------+------+-----+---------+----------------+ 4 rows in set (0.01 sec) mysql> quit; Bye
薫$ ./script/generate scaffold bm bm
exists app/controllers/
exists app/helpers/
create app/views/bm
exists app/views/layouts/
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/bm.rb
create test/unit/bm_test.rb
create test/fixtures/bms.yml
create app/views/bm/_form.rhtml
create app/views/bm/list.rhtml
create app/views/bm/show.rhtml
create app/views/bm/new.rhtml
create app/views/bm/edit.rhtml
create app/controllers/bm_controller.rb
create test/functional/bm_controller_test.rb
create app/helpers/bm_helper.rb
create app/views/layouts/bm.rhtml
create public/stylesheets/scaffold.css
コントローラはこんなカンジ。
薫$ cat app/controllers/bm_controller.rb
[src]
class BmController < ApplicationController
def index
list
render :action => 'list'
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@bm_pages, @bms = paginate :bms, :per_page => 10
end
def show
@bm = Bm.find(params[:id])
end
def new
@bm = Bm.new
end
def create
@bm = Bm.new(params[:bm])
if @bm.save
flash[:notice] = 'Bm was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
@bm = Bm.find(params[:id])
end
def update
@bm = Bm.find(params[:id])
if @bm.update_attributes(params[:bm])
flash[:notice] = 'Bm was successfully updated.'
redirect_to :action => 'show', :id => @bm
else
render :action => 'edit'
end
end
def destroy
Bm.find(params[:id]).destroy
redirect_to :action => 'list'
end
end
サーバを起動します。
ポート3000で動作します。
薫$ ./script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options
http://localhost:3000/bm にアクセスすると Listing bms と表示されます。
http://localhost:3000/bm/new で新しいエントリが追加できます。
データベースにアカウントを作成
mysql -u root -p GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON hello.* TO rails@localhost IDENTIFIED BY 'some_pass'; FLUSH PRIVILEGES;
参考
http://wiki.rubyonrails.org/rails/pages/RailsOnFreeBSD
参照しているページ (サイト内): [2009-03-17-1] [2009-03-12-1] [2009-03-06-1] [2009-03-04-1]
スポンサーリンク
スポンサーリンク
いつもシェア、ありがとうございます!
もっと情報を探しませんか?
関連記事
最近の記事
- パナソニック ジェットウォッシャードルツ EW-DJ61-Wのホースの修理
- LinuxセキュリティモジュールIntegrity Policy Enforcement
- アマゾンのEcho Show 5を買ったのでレビューします
- アマゾンのサイバーマンデーはAlexa Echo Show 5が安い
- Android スマートフォン OnePlus 7T と OnePlus 7の違い
- Android スマートフォン OnePlus 7 をAndroid10にアップデートしてみた
- クレジットカードのバーチャルカードの比較のまとめ
- 活動量計 Xiaomi Mi Band 4を買ってみたのでレビュー
- Android スマートフォン OnePlus 7 のレビュー
- AliExpressでスマートフォンを買い物してみた
- パソコンのホコリ対策 レンジフードフィルターと養生テープ
- 80PLUS GOLDのPC電源ユニットAntec NeoEco 750 Goldのレビュー
- イギリスの付加価値税 VAT は払い戻しを受けられる
- イギリスのロンドンでスーツケースなど荷物を預けられる場所は
- イギリスのロンドンで地下鉄やバスに乗るならオイスターカードを使おう
- イギリスのヒースロー空港からロンドン市内への行き方
- 航空便でほかの航空会社に乗り継ぎがある場合のオンラインチェックイン
- SFC会員がANA便ではなくベトナム航空のコードシェアを試して解ったこと
- ベトナムの入国審査でeチケットの掲示が必要だった話
- シアトルの交通ICカードはオルカカード(Orca)です
人気のページ
- Windows7 IME 辞書ツールで単語の登録に失敗しました
- C言語 popen()でコマンドを実行して出力を読み込む
- Windows7で休止状態にする方法
- CentOS MySQLの起動、停止、再起動
- loggerコマンドでsyslogにエラーを出力する方法
- パソコンパーツの買取をしてくれる店のまとめ
- Java Mapの使い方 get(),put(),remove(),size(),clear()
- 楽天のRポイントカードを作ってみた
- iPhone 5 から iPhone 6 に乗り換えたのでレビュー
- netstatコマンドのステータスの意味
スポンサーリンク
過去ログ
2020 : 01 02 03 04 05 06 07 08 09 10 11 122019 : 01 02 03 04 05 06 07 08 09 10 11 12
2018 : 01 02 03 04 05 06 07 08 09 10 11 12
2017 : 01 02 03 04 05 06 07 08 09 10 11 12
2016 : 01 02 03 04 05 06 07 08 09 10 11 12
2015 : 01 02 03 04 05 06 07 08 09 10 11 12
2014 : 01 02 03 04 05 06 07 08 09 10 11 12
2013 : 01 02 03 04 05 06 07 08 09 10 11 12
2012 : 01 02 03 04 05 06 07 08 09 10 11 12
2011 : 01 02 03 04 05 06 07 08 09 10 11 12
2010 : 01 02 03 04 05 06 07 08 09 10 11 12
2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12
2003 : 01 02 03 04 05 06 07 08 09 10 11 12