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.
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.
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.
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