How to retrieve auto incremented id in rails 4.1? -


currently working on rails 4.1,

i have model called accounts.rb,

account = account.create :name => 'test' :info => 'test' 

so statement saving database, using "account.id" auto increment id in accounts table.

but not working , showing following error,

undefined method `id' "":string   

but worked in rails 1.9 version .

please me.

object

your method seems correct; syntax seems have issue

undefined method `id' "":string 

this means you're calling id method on object string, empty 1 @ that.

i therefore problem not auto increment number, it's how you're calling id of new object

--

create

the standard way use following:

#controller account = account.create({name: "test", info: "test"}) return account.id 

according create documentation, should work you. if doesn't, may wish use .new .save methods, this:

#controller account = account.new({name: "test", info: "test"}) if account.save   return account.id end 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -