I create variables model which have two attributes name and value for saving any options in my site. What I want to know is do I need any special method like serialize to make rails recognize data type after it read or before it write to db ?
I try it without serialize :value but only data type work are array hash and string the others don't.and every things work fine, but it really is ? if yes why do rails have this serialize method.
This is my code
class CreateVariables < ActiveRecord::Migration
def self.up
create_table :variables do |t|
t.string :name
t.text :value
t.timestamps
end
add_index :variables, :name, :unique => true
end
def self.down
drop_table :variables
end
end
class Variable < ActiveRecord::Base
validates_uniqueness_of :name
validates_presence_of :name, :value
end