I have an ActiveRecord model (I'm on rails 2.3.8) called user and I'm saving it as
user = User.new user.name = "user name" user.save!
what I want to do is get the generated user id after creating the user. But currently it returns true/ false value upon saving
How can I get the saved user id?
ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending. Edit: as Mike points out, in this case ActiveRecord is a module...
ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code.
ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.
1 What is Active Record? Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.
Just call user.id
after you've saved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With