Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
ActiveRecord & Sqlite3 & serialize & "f"
Erik Veenstra
7/20/2007 7:41:00 PM
What's wrong with the code below?
It returns this "f" instead of "". Where does "f" come from?
Thanks.
gegroet,
Erik V. -
http://www.erikve...
----------------------------------------------------------------
$ ruby test.rb
:bar
"f" <<<< Should be ""
nil
$ echo "select * from key_values;" | sqlite3 test.db
1|--- :foo
|--- :bar
2|--- :empty
|f
3|--- :nil
|
----------------------------------------------------------------
require "rubygems"
require "active_record"
class KeyValue < ActiveRecord::Base
serialize :key
serialize :value
def self.create_table
unless connection.tables.include?(table_name)
connection.create_table(table_name) do |table|
table.column :id , :primary_key
table.column :key , :text
table.column :value , :text
end
end
end
def self.[](key)
find_or_create_by_key(key).value
end
def self.[]=(key, value)
config = find_or_create_by_key(key)
config.value = value
config.save
end
end
File.delete("test.db") if File.file?("test.db")
ActiveRecord::Base.establish_connection(:adapter=>"sqlite3", :database=>"test.db")
KeyValue.create_table
KeyValue[:foo] = :bar
KeyValue[:empty] = ""
KeyValue[:nil] = nil
p KeyValue[:foo]
p KeyValue[:empty]
p KeyValue[:nil]
----------------------------------------------------------------
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
ActiveRecord & Sqlite3 & serialize & "f"
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password