Ruby on Rails Model creation string not converted to integer -


here code: base_release_id column in release db integer type

form.html.haml

= form_for @release  |f|    = f.label :name   %br   = f.text_field :name   ....   = f.label :base_release_id   %br   = f.select :base_release_id, options_from_collection_for_select(conditionsplusblankorderby(release),"id","name",@release.base_release_id)   = f.submit 

releases_controller.rb

 def create     ap params     @release = release.new(params[:release])     ap @release     ...   end 

i going create new release including name , base release id etc. using 2 "ap" trace release object. strange thing happen. see log below:

 {                   "utf8" => "â",     "authenticity_token" => "8hddlc3jjxyvq+8tuh/cut5ibhxjif6l2czaforlnbg=",                "release" => {                    "name" => "e",                    "code" => "e",         "base_release_id" => "2"     },                 "commit" => "create release",                 "action" => "create",             "controller" => "releases" } #<release:0x000000190f06b8> {                  :id => nil,                :name => "e",                :code => "e",     :base_release_id => nil, }  processing releasescontroller#create html   parameters: {"utf8"=>"â", "authenticity_token"=>"8hddlc3jjxyvq+8tuh/cut5ibhxjif6l2czaforlnbg=", "release"=>{"name"=>"e", "code"=>"e", "base_release_id"=>"2"}, "commit"=>"create release"} 

not sure why base_release_id lost, name , code working. have similar code works in other page, in case parame string value don't parsed model integer?

it works if added datatype convertion below:

def create         ap params         @release = release.new(params[:release])         @release.base_release_id = params[:release][:base_release_id].to_i if params[:release][:base_release_id]         ap @release         ...       end 

please , thank in advance.

found why. in model release.rb, i'v defined "attr_accessible :id, :name, :code, :as => :tmp_use". accept id, name , code only. after added :base_release_id, works.

not sure how :as => :tmp_use work. suppose default variable can accessed. in places, using release.new("id"=>row[:id],"name"=>row[:name],"code"=>row[:code], :as => :tmp_use) places don't want want columns accessable.

no sure how.

thank ivan anyway.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -