serialization - Rails serialized integer attribute in params, but not saving into model instance -
so have following model contains serialized integer attribute
rake file:
class createcompanyassetstats < activerecord::migration def change create_table :company_asset_stats |t| t.integer :companyid t.string :geo t.integer :assettype t.date :starttime t.date :endtime t.timestamps end end end
model:
serialize :companyid, array serialize :assettype, array serialize :geo, array
in view have form have multiselect dropdown stores value(s) params:
<div class="dropdown" data-init="dropdown"> <button >multi select</button> <select name="company_asset_stats[companyid][]" multiple> <% allfieldvalues('company', 'companyname', 'company').each |value| %> <option value=<%= value[1] %>><%= value[0] %></option> <% end %> </select> </div>
the resulting param in following form: parameters: {"utf8"=>"✓", "authenticity_token"=>"2wfx3/3tyhsjobwraljyw2jt4jr5ucvtgybk3ixktqs=", "company_asset_stats"=>{"starttime"=>"2013-07-31t00:00-07:00", "endtime"=>"2013-07-31t00:00-07:00", "companyid"=>["1864"]}, "commit"=>"create"}
and create controller following:
def create @company_asset_stats = companyassetstats.new(params[:company_asset_stats]) if @company_asset_stats.save redirect_to :action => "index" else render 'new' end end
when redirected model's index however, see companyid saved 0 , assettype nothing @ all. have tried manually setting attributes in following manner:
@company_asset_stats.companyid = [1,2,3]
but same display in index.
any help?
you appear have t.integer :companyid
in database. serialized attributes cannot go integer column, instead need text column.
Comments
Post a Comment