I used a PHP function mysql_insert_id to get the ID generated from the
previous INSERT operation. I wonder if there is something similar that I
can use in Ruby/Rails?
Thanks in advance!
I used a PHP function mysql_insert_id to get the ID generated from the
previous INSERT operation. I wonder if there is something similar that I
can use in Ruby/Rails?
Thanks in advance!
Once you save @object, just use @object.id.
–
Building an e-commerce site with Rails?
http://agilewebdevelopment.com/rails-ecommerce
Meet up at RailsConf:
http://railsconf2007.conferencemeetup.com/
Benjamin C. wrote:
Once you save @object, just use @object.id.
Thanks Benjamin. So you mean @object.id will be the auto-increment id
created in MySql?
All I want to do is that - in one single page, allow people to sign up
for a company and register for many users (in the same company). Once
user clicks submit, it will first create the company (i.e. insert into
company table and return id) and then add each user to users table
(using the same company_id)
On Apr 13, 2007, at 5:43 PM, Gordon Lo wrote:
user clicks submit, it will first create the company (i.e. insert into
company table and return id) and then add each user to users table
(using the same company_id)
Yes, it is the id provided by MySQL. Assuming you have the
relationship between company and users in your models, you can also
do something like this:
@company = Company.create(params[:company])
params[:users].each do |user|
@company.users.create(user)
end
–
Building an e-commerce site with Rails?
http://agilewebdevelopment.com/rails-ecommerce
Meet up at RailsConf:
http://railsconf2007.conferencemeetup.com/
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs