On 21 August 2015 at 11:46, Milley Duke <li...@ruby-forum.com> wrote:
> 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.

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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs9TOztAL5myZnZciimQt7iGQS1g0n4eWRshe9kFPN3Ow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to