Archive for the ‘Programing’ Category

restful_authentication導入その1

金曜日, 8月 22nd, 2008

昨日の手順に従って実施。

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 \
–stateful

The 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 option

config.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

今日はここまで

Tags: ,
Posted in Programing | No Comments »

restful_authentication使うぜ!

木曜日, 8月 21st, 2008

って、今日も寝坊して、触れず、、、

一応作業手順概要をまとめた。

明日こそ、、、

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のインストールが必要

Tags:
Posted in Programing | No Comments »

Railsでユーザ認証

水曜日, 8月 20th, 2008

Railsでユーザ認証を今日朝したかったけど、寝坊してできなかった。。。

ってことで、情報まとめ編。
明日作ります。

SHOWZINE ≫ restful_authenticationによるユーザ認証を実装

ユーザ認証用のプラグインの導入とテーブルの生成 – Okiraku Programming

ユーザ認証用のプラグインの導入とテーブルの生成 – Okiraku Programming

restful_authentication を題材にして routes, resource and resources のお勉強 – noplans_rubyの日記

restful_authenticationを触ってみた – idesaku blog

ZDNet Japan Blog – あとで読むRailsのススメ:restful_authentication

Tags:
Posted in Programing | No Comments »

Rails2.0でscaffoldする。

火曜日, 8月 19th, 2008

Rails2.0の壁にぶち当たった昨日の続き。

昨日の「こうすりゃいんじゃね?」まとめ。
——————————————————-
1.db内にデータベース作成する。
2.初期ウィザードで、Mysql指定(これでdatabase.ymlも自動生成)
3.scaffold生成
4.mygrationファイル修正
5.mygrate
6.実行!
——————————————————-

で、今日やってみました。
おおむねOK

忘れないうちに備忘録
——————————————————-
■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 1
Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> drop database rubyweblog_development;
Query OK, 2 rows affected (0.64 sec)

mysql> create database rubyweblog_development;
Query OK, 1 row affected (0.03 sec)

mysql> quit;
Bye

昨日のゴミDBを消して、作っただけ。

■2.初期ウィザードで、Mysql指定(これでdatabase.ymlも自動生成)

NetBeansのプロジェクト作成ウィザードで指定しただけ。(簡単!)

■3.scaffold生成

プロジェクト名を右クリック→「生成」を選択

生成で「scaffold」を選択
名前で「Post title:string」を入力
「了解」ボタンを選択

■4.mygrationファイル修正

修正不要。勝手にgenerateしてくれています。

■5.mygrate

プロジェクト名を右クリック>データベースマイグレーション>現在のバージョン

■6.実行!
失敗!

#良く考えたら、構成とかの編集忘れてました。

■7.構成の編集
<appフォルダ>\config\routes.rb の編集
# map.root :controller => “welcome”

map.root :controller => “posts”

※ここで指定するコントローラ名は複数系。これで軽くはまりました。

■8.デフォルトindexファイル削除
<appフォルダ>\public\index.html を削除

■9.再実行
OK!
——————————————————-

ってか、1.2系より、よっぽど簡単。これは2.0で開発進めるべきか。。。
#自動生成されているソースもわかりやすくなっている。マイグレーションファイル名が、タイムスタンプになってたりとか
#20080818225201_create_posts.rb

Tags: , ,
Posted in Programing | No Comments »

NetBeans チュートリアル進まず(おそらくrails1.2系とrails2.0系の違い)

月曜日, 8月 18th, 2008

Databaseは作成できたが、チュートリアルどおり進まない。

NoMethodError in BlogController#index

undefined method `title’ for BlogController:Class

RAILS_ROOT: C:/Documents and Settings/Miyai/My Documents/NetBeansProjects/rubyweblog
Application Trace | Framework Trace | Full Trace

app/controllers/blog_controller.rb:2

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:215:in `load_without_new_constant_marking’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:215:in `load_file’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:214:in `load_file’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:95:in `require_or_load’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:260:in `load_missing_constant’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:467:in `const_missing’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:479:in `const_missing’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/inflector.rb:283:in `constantize’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/string/inflections.rb:143:in `constantize’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/route_set.rb:386:in `recognize’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:148:in `handle_request’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in `handle_dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in `service’
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread’
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread’
C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each’
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
script/server:3

app/controllers/blog_controller.rb:2
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:215:in `load_without_new_constant_marking’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:215:in `load_file’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:214:in `load_file’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:95:in `require_or_load’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:260:in `load_missing_constant’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:467:in `const_missing’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:479:in `const_missing’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/inflector.rb:283:in `constantize’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/string/inflections.rb:143:in `constantize’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/route_set.rb:386:in `recognize’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:148:in `handle_request’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in `handle_dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in `service’
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread’
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread’
C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each’
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start’
C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in `dispatch’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in’
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require’
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
script/server:3

Request

Parameters:

None

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=>[],
“Cache-Control”=>”no-cache”}

おそらく、rails1.2系と、rails2.0系のscaffoldに違いによるエラー

教えて! Watch Ruby on Rails について

——————————————————-
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.実行!
——————————————————-

明日やってみる。

■他、参考サイト
Ruby on Rails 2.0以降 scaffoldの違い – 『どこでもドア的』プロジェクト

Tags:
Posted in Cocoya.net, Programing | No Comments »

MysqlでDatabase作成

月曜日, 8月 18th, 2008

NetBeansのチュートリアルに沿って、初期プロジェクトを作成したが、Databaseの作成に失敗する。

■なぜか、データベースが作成できない。
C:\Documents and Settings\Miyai>mysqladmin -u root -p create rubyweblog_development
Enter password: ********
mysqladmin: CREATE DATABASE failed; error: ‘Can’t create database ‘rubyweblog_development’; 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_development
Enter password: ********
mysqladmin: CREATE DATABASE failed; error: ‘Can’t create database ‘rubyweblog_development’; 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 exists

■どうやら、すでに同名のデータベースがある模様。(アンインストールに失敗していた?)
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>

Tags: ,
Posted in Cocoya.net, Programing | No Comments »

Get Adobe Flash playerPlugin by wpburn.com wordpress themes