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?

--
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+unsubscribe@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/f7ad5eb5-1760-4748-b84c-b398fdf8cedd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Colin Law at Apr 27, 2015 at 9:07 am

    On 27 April 2015 at 09:42, Padmahas Bn wrote:
    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?
    Why not? Presumably inside processrecovery.

    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+unsubscribe@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%3D0gLuZO4gES3qFO17aSwQ4U_Wm0M0P0tnSK2BQr1vm5SBEyQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Padmahas Bn at Apr 27, 2015 at 11:23 am
    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.

    --
    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+unsubscribe@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/79f30165-dc73-4e64-948e-384d24f14fc7%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Apr 27, 2015 at 12:37 pm

    On 27 April 2015 at 12:23, Padmahas Bn 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
    http://guides.rubyonrails.org/active_record_basics.html
    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

    --
    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+unsubscribe@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%3D0gLtW0jNNjTy2hGxr%3DBg-jiZs7YKJ%3DR1OQq3Lm_F2LYaR2Q%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Padmahas Bn at Apr 27, 2015 at 1:04 pm

    Of course, see section 5 of
    http://guides.rubyonrails.org/active_record_basics.html
    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.
    Sound like good new for me even though it is not recommended.

    Anyway Thank you Collin

    --
    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+unsubscribe@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/e6cd18d3-0b50-4b22-8cc7-7398ea55f000%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Hassan Schroeder at Apr 27, 2015 at 2:50 pm

    On Mon, Apr 27, 2015 at 6:04 AM, Padmahas Bn wrote:

    http://guides.rubyonrails.org/active_record_basics.html
    Sound like good new for me even though it is not recommended.
    What is it you believe is "not recommended"?

    --
    Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan
    Consulting Availability : Silicon Valley or remote

    --
    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+unsubscribe@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/CACmC4yCCf8yHWqEOf%3DHeCx8qKiFTmVo0Uw7T9dF-_kp%3DEHXU7Q%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Padmahas Bn at Apr 29, 2015 at 4:08 pm
    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.

    --
    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+unsubscribe@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/2294808e-49c5-4623-b433-7dbacb2ee7e8%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Hassan Schroeder at Apr 29, 2015 at 8:15 pm

    On Wed, Apr 29, 2015 at 9:08 AM, Padmahas Bn 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 Schroeder ------------------------ hassan.schroeder@gmail.com
    http://about.me/hassanschroeder
    twitter: @hassan
    Consulting Availability : Silicon Valley or remote

    --
    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+unsubscribe@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/CACmC4yBJhSzM%3D1XhXiZ9O6XDJacZ_gz%3DVjwAdw71ojSvSjRXhw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 27, '15 at 8:42a
activeApr 29, '15 at 8:15p
posts8
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase