Insert data into multiple tables

Hi,

Is there any way to insert data when form is saved into another table.

Say for example:

I have membership table which already contains some data and have column
names as ‘no_of_users_added’, ‘no_of_users_left’.

I want to insert data from user table based on the count value how many
users are saved and the corresponding column values (‘no_of_users_added’
and ‘no_of_users_left’) gets updated into the Membership table.

Please help me resolving this issue.

Regards,
Milley

Look at ActiveModel::Dirty,
specifically method changed? at
ActiveModel::Dirty, and
changed (ActiveRecord::Dirty) - APIdock

On 21 August 2015 at 11:46, Milley D. [email protected] wrote:

users are saved and the corresponding column values (‘no_of_users_added’
and ‘no_of_users_left’) gets updated into the Membership table.

You can write records to any table you like from any controller. So
to add a new record just use ModelName.new, set the values as
appropriate and save it. However generally it is bad practice to save
anything that can be calculated on the fly, and I rather suspect that
at least one of the values you mention may fall into that category,
posibly both. You may think it is a worthwhile efficiency saving but
the bottlenecks in an app are very rarely where you expect them to be.
There are many issues to be thought about when saving data that can be
calculated. Suppose for example the server crashes at an unfortunate
moment such that you end up with the saved value not representing the
calculated value.

Colin