|
|
||
解決しました!DBI標準で入ってるとばっかり orz
以下のパッケージを追加インストール。
||/ 名前 バージョン 説明 +++-=============================-=============================-========================================================================== ii libdbd-mysql-ruby1.8 0.1.1-4 Ruby/DBI MySQL driver for Ruby 1.8 ii libdbi-ruby1.8 0.1.1-4 Database Independent Interface for Ruby 1.8 ii libmysql-ruby1.8 2.7.3-1 MySQL module for Ruby 1.8
# db:migrate (in /home/syudou/rails/hello) == CreateMessages: migrating ================================================== -- create_table(:messages) -> 0.5195s == CreateMessages: migrated (0.5197s) =========================================
やっと次に進める:)
先週からrailsの勉強を始めたのですが、昨日からマイグレーションの実行ではまっています。
お分かりの方がいましたら助言お願いします。
参考書籍はこちらです。
現在、p136 のマイグレーションの実行で結果が合いません。
debian GNU/Linux sid
プロジェクト作成とDB作成
# cd ~ # mkdir rails # cd rails # rails hello # mysqladmin create hello -p
# vi config/database.yml development: adapter: mysql database: hello username: syudou password: dbpass host: localhost
# ruby script/generate model Message
create app/models/
create test/unit/
create test/fixtures/
create app/models/message.rb
create test/unit/message_test.rb
create test/fixtures/messages.yml
exists db/migrate
create db/migrate/001_create_messages.rb
# vi db/migrate/001_create_messages.rb
class CreateMessages < ActiveRecord::Migration
def self.up
create_table :messages do |t|
t.column :name, :string
t.column :value, :string
end
end
def self.down
drop_table :messages
end
end
# rake db:migrate (in /home/syudou/rails/hello) rake aborted! wrong number of arguments (1 for 0) (See full trace by running task with --trace)
# rake db:migrate --trace (in /home/syudou/rails/hello) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate rake aborted! wrong number of arguments (1 for 0) /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:551:in `initialize' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:551:in `new' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:551:in `scramble41' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:141:in `real_connect' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:330:in `connect' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:87:in `initialize' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:36:in `new' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:36:in `mysql_connection' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in `send' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in `connection_without_query_cache=' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/query_cache.rb:54:in `connection=' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in `retrieve_connection' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection' /home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate' /home/syudou/rails/hello/config/../vendor/rails/railties/lib/tasks/databases.rake:4 /usr/lib/ruby/1.8/rake.rb:387:in `call' /usr/lib/ruby/1.8/rake.rb:387:in `execute' /usr/lib/ruby/1.8/rake.rb:387:in `each' /usr/lib/ruby/1.8/rake.rb:387:in `execute' /usr/lib/ruby/1.8/rake.rb:357:in `invoke' /usr/lib/ruby/1.8/rake.rb:350:in `synchronize' /usr/lib/ruby/1.8/rake.rb:350:in `invoke' /usr/lib/ruby/1.8/rake.rb:1924:in `run' /usr/lib/ruby/1.8/rake.rb:1924:in `each' /usr/lib/ruby/1.8/rake.rb:1924:in `run' /usr/bin/rake:4
# mysql hello -u syudou -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.0.38-Debian_1-log Debian etch distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> SELECT * FROM mysql.user WHERE User='syudou' \G
*************************** 1. row ***************************
Host: %
User: syudou
Password: *FA772E0932809535E43FEDEA5BC7473E262670AF
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
*************************** 2. row ***************************
Host: localhost
User: syudou
Password: *FA772E0932809535E43FEDEA5BC7473E262670AF
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
2 rows in set (0.00 sec)
grep的な使い方をかなり多用します。いつもこんな感じで書いてます。
$file = "./hogefile" $pat = "hoge" open($file){|file| while line = file.gets if line.scan(/.*#{$pat} .*/).size.to_i >= 1 puts line end end }
サイト見てたら、
$file = "./hogefile" $pat = "hoge" open($file){|file| while line = file.gets if line =~ /.*#{$pat}.*/ puts line end end }
でやってる。.scan にこだわり過ぎてた。
muscovyduck「if line =~ /.*#{$pat}.*/」は「if line.match($pat)」でもいいかもしれませんね。
rsyudouif line.match($pat) なるほど便利。どうもです。
はてなブックマークトップページ(Index.html)からブックマーク数だけ抜き取りたい場合
# get entory bookmark open($indexfile){|file| while l = file.gets if l =~ /.*0.7em.*/ # get entory_count $hb_e = l.to_s.sub(/.*\">/,"").gsub(",","").sub(/\s.*$/,"") # get bookmark_count $hb_b = l.to_s.sub(/.*\">/,"").sub(/\s\D*$/,"").gsub(",","").sub(/.*\s.*\D/,"") end end }
もっとうまくできないかな。
よろしくお願いします。
$tempfile = Tempfile::new("hoge", "/tmp")
できた。