ruby on rails - Hash Table Column Values as Integer -


i have followed this tutorial have hash column on model works great.

when work out codes in rails console, becomes different within controller code. in console:

foo.update_attributes(bar: {"a" => 1, "b" => 2}) 

my values shown integer, in console. in controller, if i'm doing calculations, have add .to_i or .to_f , becomes messy. values forever number. can simple add int or float column?

add_column :foos, :bar, :hstore, :integer, default: {}, null: false 

the above not work.

you can use hook on model:

before_save -> r { r.bar.each{|k, v| r.bar[k] = v.to_i} } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -