Archive for 8月, 2008
Lenovo note NetBeans開発環境
ruby インストール
・One-Click Ruby
ruby186-26.exe
システム環境変数の”path”に追加
;C:\ruby\bin
・MySQL
mysql-essential-5.0.51b-win32.msi
default character を utf8 に変更
Include Bin Directory in Windows PATHにチェックオン
・Rails
gemsでインストール
> gem install rails
c:\ruby>gem install rails
Bulk updating Gem source index for: http://gems.rubyforge.org
Install required dependency rake? [Yn] Y
Install required dependency activesupport? [Yn] Y
Install required dependency activerecord? [Yn] Y
Install required dependency actionpack? [Yn] Y
Install required dependency actionmailer? [Yn] Y
Install required dependency activeresource? [Yn] Y
Successfully installed rails-2.1.0
Successfully installed rake-0.8.1
Successfully installed activesupport-2.1.0
Successfully installed activerecord-2.1.0
Successfully installed actionpack-2.1.0
Successfully installed actionmailer-2.1.0
Successfully installed activeresource-2.1.0
Installing ri documentation for rake-0.8.1…
Installing ri documentation for activesupport-2.1.0…
Installing ri documentation for activerecord-2.1.0…
Installing ri documentation for actionpack-2.1.0…
Installing ri documentation for actionmailer-2.1.0…
Installing ri documentation for activeresource-2.1.0…
Installing RDoc documentation for rake-0.8.1…
Installing RDoc documentation for activesupport-2.1.0…
Installing RDoc documentation for activerecord-2.1.0…
Installing RDoc documentation for actionpack-2.1.0…
Installing RDoc documentation for actionmailer-2.1.0…
Installing RDoc documentation for activeresource-2.1.0…
c:\ruby>gem install rails
Successfully installed rails-2.1.0
インストール許可を省略する際には”-y”オプション
> gem install rails -y
1.2系をインストールする場合は以下参照
> gem install rails –version=”1.2.6″ -y
C:\Documents and Settings\Miyai>mysql –version
mysql Ver 14.12 Distrib 5.0.51b, for Win32 (ia32)
C:\Documents and Settings\Miyai>rails -v
Rails 2.1.0
C:\Documents and Settings\Miyai>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
・NetBeansインストール
JDKが必要
http://java.sun.com/j2se/1.5.0/ja/download.html
netbeans-6.1-ml-ruby-windows.exe
※mlはマルチランゲージの事。日本語版を含みます。
チュートリアル
http://www.netbeans.org/kb/60/ruby/rapid-ruby-weblog_ja.html
■なぜか、データベースが作成できない。
C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_developm
ent
Enter password: ********
mysqladmin: CREATE DATABASE failed; error: ‘Can’t create database ‘rubyweblog_de
velopment’; database exists’
C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> quit;
Bye
C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_developm
ent
Enter password: ********
mysqladmin: CREATE DATABASE failed; error: ‘Can’t create database ‘rubyweblog_de
velopment’; database exists’
C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> quit;
Bye
C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> create database rubyweblog_development;
ERROR 1007 (HY000): Can’t create database ‘rubyweblog_development’; database exi
sts
■どうやら同名のデータベースがある模様。(アンインストール失敗していた?)
mysql> show databases;
+————————+
| Database |
+————————+
| information_schema |
| depot_development |
| mysql |
| rubyweblog_development |
| test |
+————————+
5 rows in set (0.23 sec)
■不要なデータベースを削除
mysql> drop database depot_development;
Query OK, 2 rows affected (0.33 sec)
mysql> drop database rubyweblog_development;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.02 sec)
mysql> quit;
Bye
■無事作成できた。
C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_development
Enter password: ********
C:\Documents and Settings\Miyai>
■しかし、チュートリアルどおり進まない。
rails1.2系と、rails2.0系の違い
教えて! Watch Ruby on Rails について
http://oshiete1.watch.impress.co.jp/qa4070054.html
始める。 ・テンプレートファイルの名称がXXX.rhtmlからXXX.html.erbに変更 ってとこです。
http://yamamoto.xrea.jp/2008/02/ruby-on-rails-20scaffold.php
——————————————————-
1.railsコマンドでひな形を作成
※rails2.0ではデフォルトのDBがSQLite3なので、mysqlで使う場合は”-d mysql”オプションが必要かもです。
2.database.ymlを修正
3.おもむろにscaffold実行
ruby script/generate scaffold pepole name:string age:integer
4.dbにデータベースを作る
5.mygrateする
rake db:migrate
6.serverをスタートする
——————————————————-
↓
NetBeansのチュートリアル手順を改造するとこんな感じか
——————————————————-
1.db内にデータベース作成する。
2.初期ウィザードで、Mysql指定(これでdatabase.ymlも自動生成)
3.scaffold生成
4.mygrationファイル修正
5.mygrate
6.実行!
——————————————————-
明日やってみる。
昨日の手順に従って実施。
1.DBの作成
C:\Documents and Settings\Miyai>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> create database rubyweblog_development;
Query OK, 1 row affected (0.00 sec)mysql> show databases;
+————————+
| Database |
+————————+
| information_schema |
| mysql |
| rubyweblog_development |
+————————+
3 rows in set (0.00 sec)mysql>
2.railsプロジェクトの作成
rubyweblog作った!
3. restful_authentication プラグインのインストール
$ ./script/plugin discover
C:\Documents and Settings\Miyai\My Documents\NetBeansProjects\rubyweblog>ruby script/plugin discover
Add http://www.agilewebdevelopment.com/plugins/? [Y/n] Y
Add svn://rubyforge.org/var/svn/expressica/plugins/? [Y/n] Y
Add http://soen.ca/svn/projects/rails/plugins/? [Y/n] Y
Add http://technoweenie.stikipad.com/plugins/? [Y/n] Y
Add http://svn.techno-weenie.net/projects/plugins/? [Y/n] Y
Add http://svn.recentrambles.com/plugins/? [Y/n] Y
Add http://opensvn.csie.org/rails_file_column/plugins/? [Y/n] Y
Add http://svn.protocool.com/public/plugins/? [Y/n] Y
Add http://tools.assembla.com/svn/breakout/breakout/vendor/plugins/? [Y/n] Y
Add http://svn.pragprog.com/Public/plugins/? [Y/n] Y
Add http://source.collectiveidea.com/public/rails/plugins/? [Y/n] Y
Add https://secure.near-time.com/svn/plugins/? [Y/n] Y
Add http://svn.inlet-media.de/svn/rails_extensions/plugins/? [Y/n] Y
Add http://svn.viney.net.nz/things/rails/plugins/? [Y/n] y
Add http://svn.hasmanythrough.com/public/plugins/? [Y/n] y
Add http://svn.shiftnetwork.com/plugins/? [Y/n] y
Add svn://caboo.se/plugins/? [Y/n] y
Add http://svn.6brand.com/projects/plugins/? [Y/n] y
Add http://shanesbrain.net/svn/rails/plugins/? [Y/n] y
Add svn://errtheblog.com/svn/plugins/? [Y/n] y
Add http://svn.nkryptic.com/plugins/? [Y/n] y
Add http://svn.thoughtbot.com/plugins/? [Y/n] y
Add http://svn.webwideconsulting.com/plugins/? [Y/n] y
Add http://invisible.ch/svn/projects/plugins/? [Y/n] y
Add svn://rubyforge.org/var/svn/enum-column/plugins/? [Y/n] y
Add http://hivelogic.com/plugins/? [Y/n] y
Add http://mattmccray.com/svn/rails/plugins/? [Y/n] y
Add svn://rubyforge.org/var/svn/cartographer/plugins/? [Y/n] y
Add http://www.svn.recentrambles.com/plugins/? [Y/n] y
Add http://tanjero.com/svn/plugins/? [Y/n] y
Add http://filetofsole.org/svn/public/projects/rails/plugins/? [Y/n] y
Add http://topfunky.net/svn/plugins/? [Y/n] y
Add svn://rubyforge.org/var/svn/agtools/plugins/? [Y/n] y
Add http://svn.aviditybytes.com/rails/plugins/? [Y/n] y
Add http://beautifulpixel.textdriven.com/svn/plugins/? [Y/n] y
Add http://mabs29.googlecode.com/svn/trunk/plugins/? [Y/n] y
Add http://www.codyfauser.com/svn/projects/plugins/? [Y/n] y
Add http://craz8.com/svn/trunk/plugins/? [Y/n] y
Add http://sean.treadway.info/svn/plugins/? [Y/n] y
Add http://svn.thebootstrapnation.com/public/plugins/? [Y/n] y
Add http://www.mattmccray.com/svn/rails/plugins/? [Y/n] y
Add svn://rubyforge.org//var/svn/validaterequest/plugins/? [Y/n] y
Add http://sprocket.slackworks.com/svn/rails/plugins/? [Y/n] y
Add http://svn.simpltry.com/plugins/? [Y/n] y
Add http://svn.elctech.com/svn/public/plugins/? [Y/n] y
Add http://xmlblog.stikipad.com/plugins/? [Y/n] y
Add http://www.xml-blog.com/svn/plugins/? [Y/n] y
Add http://svn.toolbocks.com/plugins/? [Y/n] y
Add http://thar.be/svn/projects/plugins/? [Y/n] y
Add http://code.teytek.com/rails/plugins/? [Y/n] y
Add http://www.infused.org/svn/plugins/? [Y/n] y
Add svn://rubyforge.org/var/svn/apptrain/trunk/vendor/plugins/? [Y/n] y
Add http://s3cachestore.googlecode.com/svn/trunk/plugins/? [Y/n] y
Add http://sbecker.net/shared/plugins/? [Y/n] y
Add http://opensvn.csie.org/macaque/plugins/? [Y/n] y
Add http://svn.designbyfront.com/rails/plugins/? [Y/n] y
Add http://svn.rails-engines.org/plugins/? [Y/n] y
Add http://john.guen.in/svn/plugins/? [Y/n] y
Add http://www.redhillonrails.org/svn/trunk/vendor/plugins/? [Y/n] y
Add svn://rubyforge.org/var/svn/actsdisjoint/plugins/? [Y/n] y
Add http://ajaxmessaging.googlecode.com/svn/trunk/plugins/? [Y/n] y
Add http://mod-i18n.googlecode.com/svn/trunk/plugins/? [Y/n] y
Add svn://majakari.net/public/rails/plugins/? [Y/n] y
Add http://svn.devjavu.com/malaysia-rb/plugins/? [Y/n] y
Add http://svn.railslodge.com/svn/plugins/? [Y/n] y
Add http://flouzometer.rubyforge.org/svn/trunk/plugins/? [Y/n] y
Add svn://svn.spattendesign.com/svn/plugins/? [Y/n] y
Add http://rails.sanityinc.com/plugins/? [Y/n] y
Add http://svn.savvica.com/public/plugins/? [Y/n] y
Add https://svn01.allmyfunds.com.au/svn/public/plugins/? [Y/n] y
Add http://svn.megablaix.com/plugins/? [Y/n] y
Add http://to-json-options.rubyforge.org/svn/trunk/plugins/? [Y/n] y
Add http://rails-multifielddate-plugin.googlecode.com/svn/plugins/? [Y/n] y
Add http://flexible-rails.googlecode.com/svn/trunk/plugins/? [Y/n] y
Add http://sql-helper.rubyforge.org/svn/trunk/plugins/? [Y/n] y
Add http://winnscriptatype.rubyforge.org/svn/plugins/? [Y/n] y
Add svn://furtherin.net/rails/plugins/? [Y/n] y
Add http://dectxn.rubyforge.org/svn/tags/CURRENT/plugins/? [Y/n] y
$ ./script/plugin install restful_authentication
C:\Documents and Settings\Miyai\My Documents\NetBeansProjects\rubyweblog>ruby script/plugin install restful_authentication
+ ./README
+ ./Rakefile
+ ./generators/authenticated/USAGE
+ ./generators/authenticated/authenticated_generator.rb
+ ./generators/authenticated/templates/activation.html.erb
+ ./generators/authenticated/templates/authenticated_system.rb
+ ./generators/authenticated/templates/authenticated_test_helper.rb
+ ./generators/authenticated/templates/controller.rb
+ ./generators/authenticated/templates/fixtures.yml
+ ./generators/authenticated/templates/functional_spec.rb
+ ./generators/authenticated/templates/functional_test.rb
+ ./generators/authenticated/templates/helper.rb
+ ./generators/authenticated/templates/login.html.erb
+ ./generators/authenticated/templates/mailer.rb
+ ./generators/authenticated/templates/mailer_test.rb
+ ./generators/authenticated/templates/migration.rb
+ ./generators/authenticated/templates/model.rb
+ ./generators/authenticated/templates/model_controller.rb
+ ./generators/authenticated/templates/model_functional_spec.rb
+ ./generators/authenticated/templates/model_functional_test.rb
+ ./generators/authenticated/templates/model_helper.rb
+ ./generators/authenticated/templates/observer.rb
+ ./generators/authenticated/templates/signup.html.erb
+ ./generators/authenticated/templates/signup_notification.html.erb
+ ./generators/authenticated/templates/unit_spec.rb
+ ./generators/authenticated/templates/unit_test.rb
+ ./install.rb
+ ./lib/restful_authentication/rails_commands.rb
Restful Authentication Generator
====This is a basic restful authentication generator for rails, taken
from acts as authenticated. Currently it requires Rails 1.2.6 or above.To use:
./script/generate authenticated user sessions \
–include-activation \
–statefulThe first parameter specifies the model that gets created in signup
(typically a user or account model). A model with migration is
created, as well as a basic controller with the create method.The second parameter specifies the sessions controller name. This is
the controller that handles the actual login/logout function on the
site.The third parameter (–include-activation) generates the code for a
ActionMailer and its respective Activation Code through email.The fourth (–stateful) builds in support for acts_as_state_machine
and generates activation code. This was taken from:http://www.vaporbase.com/postings/stateful_authentication
You can pass –skip-migration to skip the user migration.
If you’re using acts_as_state_machine, define your users resource like this:
map.resources :users, :member => { :suspend => :put,
:unsuspend => :put,
:purge => :delete }Also, add an observer to config/environment.rb if you chose the
–include-activation optionconfig.active_record.observers = :user_observer # or whatever you
# named your model
Security Alert
====I introduced a change to the model controller that’s been tripping
folks up on Rails 2.0. The change was added as a suggestion to help
combat session fixation attacks. However, this resets the Form
Authentication token used by Request Forgery Protection. I’ve left
it out now, since Rails 1.2.6 and Rails 2.0 will both stop session
fixation attacks anyway.
■おまけ
> ruby script/plugin discover
は、リポジトリの追加
Rails Wiki – プラグイン
Plugins in Ruby on Rails
今日はここまで
なんでやろ、画像がアップできない。
wordpress上は登録できたっぽい感じですが、リンク先として指定される以下のフォルダパスがない状態。
http://www.miyai.jp/blog/wp-content/uploads/20080821_01.jpg
uploads、ってフォルダがFTPで見てもない。
って、今日も寝坊して、触れず、、、
一応作業手順概要をまとめた。
明日こそ、、、
restful_authenticationの導入
——————————————————-
1.DBの作成
2.railsプロジェクトの作成
3. restful_authentication プラグインのインストール
$ ./script/plugin discover
$ ./script/plugin install restful_authentication
#plugin descoverってなんじゃ?
→後で調べる
4. ジェネレータコマンド「authenticated」 が追加されるので、実行
activationもstateful も入れる
$ ./script/generate authenticated user sessions –include-activation –stateful
こんな感じ。
5. acts_as_state_machine プラグインもインストール
activationとかstatefulとかに必要らしい。
$ ./script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk/
6.migrate!(マイグレーション用ファイルは、上記のジェネレート時に設定済み)
7. AuthenticationSystemの組み込み
app/controller/application.rb
の
class ApplicationController < ActionController::Base
の下に
include AuthenticatedSystem # 追記
before_filter :login_from_cookie # 追記
とかを追記
8. routes.rb の編集
activateするために必要らしい。
map.connect “activate/:activation_code”, :controller => “users”, :action => “activate”
——————————————————-
■参考情報
authenticatedジェネレートのオプション
user
モデル名。同じ名前で登録関係のコントローラも作成される。以前のデフォルトでは、userモデルと登録のためのaccountコントローラだったけど、今回は両方とも同じ名前で作られる
sessions
ログインログアウト用コントローラ名。ログイン情報自体を一つのリソースとしてみなしているんだね。面白い。
–include-activation
メール認証を行うかどうか。最初の登録は仮登録で、届いたメールに書かれてるアドレスにアクセスすると登録が完了するってやつだね。以前は公式でやり方は 紹介されていたけど、自分で実装する必要があった部分。でもobserver使うやり方は好きじゃないので、うちでは使ってなかった
–stateful
プラグインacts_as_state_machineを使ってユーザの状態管理をする。仮登録状態とか、正会員とか、退会とかね。そんな状態をいくつか 定義しておいて、状態Aから状態Bに変わった時にはCという処理を行う、といったことをacts_as_state_machineを使うことで簡潔に書 くことができる。利用には別途acts_as_state_machineのインストールが必要
Railsでユーザ認証を今日朝したかったけど、寝坊してできなかった。。。
ってことで、情報まとめ編。
明日作ります。
SHOWZINE ≫ restful_authenticationによるユーザ認証を実装
ユーザ認証用のプラグインの導入とテーブルの生成 – Okiraku Programming
ユーザ認証用のプラグインの導入とテーブルの生成 – Okiraku Programming
restful_authentication を題材にして routes, resource and resources のお勉強 – noplans_rubyの日記
解析用のHTMLタグが、ブログパーツになっているらしい。
当然ですが、ブログパーツを見れないように加工した場合は、解析サービスの提供はストップされるそうです。
うーん、サービス自体は魅力的ですが、あんまり見える形では設置したくないなぁ




