class Recovery < ActiveRecord::Base
def self.processrecovery
@members = Member.where(record_status: “1”)
@members.each do |member|
tmemberCode = member.member_code
:
:
:# Processing of data from different database
:
:
# Variables containing processed data
interest_to_be_paid
pInstallmentAmt = tPersonalLoanBalAmt * tpersonalintrate / (100 *
12)
jInstallmentAmt = tJointLoanBalAmt * tjointintrate / (100 * 12)
end
end
Now how can I insert these processed data into recoveries table?
Should I user
Recovery.create(interest: => interest_to_be_paid, p_installement: =>
pInstallmentAmt,…)
inside recovery.rb (model) itself?
On 27 April 2015 at 09:42, Padmahas Bn [email protected] wrote:
# Variables containing processed data
Recovery.create(interest: => interest_to_be_paid, p_installement: =>
pInstallmentAmt,…)
inside recovery.rb (model) itself?
Why not? Presumably inside processrecovery.
Colin
Why not? Presumably inside processrecovery.
I didn’t get you. Do you mean I can use Recovery.create(…) directly
inside processrecovery without sending them to controller?
If so how can I use params? Because I suspect Rails 4 won’t let me to
directly insert data to tables without using strong parameters by
permitting them.
Thank you.
On 27 April 2015 at 12:23, Padmahas Bn [email protected] wrote:
Why not? Presumably inside processrecovery.
I didn’t get you. Do you mean I can use Recovery.create(…) directly inside
processrecovery without sending them to controller?
Of course, see section 5 of
If so how can I use params? Because I suspect Rails 4 won’t let me to
directly insert data to tables without using strong parameters by permitting
them.
In Rails 4 the protection has been moved out of the model and into the
controller. You can do anything you like while manipulating models
directly rather than through controllers.
Colin
On Mon, Apr 27, 2015 at 6:04 AM, Padmahas Bn [email protected] wrote:
Active Record Basics — Ruby on Rails Guides
Sound like good new for me even though it is not recommended.
What is it you believe is “not recommended”?
–
Hassan S. ------------------------ [email protected]
twitter: @hassan
Consulting Availability : Silicon Valley or remote
What is it you believe is “not recommended”?
I mean that I’m not using association between tables when it is possible
to
easily cascade changes done in one table, And I’ve not seen anywhere
inserting records through model directly and it’s not even showed as
example in rails guides.
So I think the way of coding that I’m doing has to be improved and code
has
to be optimized.
On Wed, Apr 29, 2015 at 9:08 AM, Padmahas Bn [email protected] wrote:
I mean that I’m not using association between tables when it is possible to
easily cascade changes done in one table,
I’m afraid I don’t understand that sentence,
And I’ve not seen anywhere inserting records through model directly
?? From your original example:
class Recovery < ActiveRecord::Base
def self.processrecovery
# do whatever
create(interest: interest_to_be_paid, p_installment:
pInstallmentAmt)
end
end
And there you go, you’ve created a new Recovery object and saved
it to the database.
Try thinking less in terms of “tables” and more in terms of “objects”
and let ActiveRecord do its job as ORM
FWIW,
Hassan S. ------------------------ [email protected]
twitter: @hassan
Consulting Availability : Silicon Valley or remote