Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:08:19+00:00 2026-06-08T03:08:19+00:00

I need to call method for user, which has email parametr. It is function

  • 0

I need to call method for user, which has email parametr. It is function for paying in PayPal and I’m setting return url and cancel url.

Here is my method, in user.rb:

   def pay email
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
credentials = {
    'USER' => 'payer_1342623102_biz_api1.gmail.com',
   'PWD' => '1342623141',
   'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
 }

header =  {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
               "X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
               "X-PAYPAL-SECURITY-SIGNATURE" =>"Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
               "X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
               "X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
               "X-PAYPAL-APPLICATION-ID" =>  "APP-80W284485P519543T"
                }
data = {"actionType" => "PAY",
           "receiverList.receiver(0).email"=> email,
           "receiverList.receiver(0).amount" => "10",
           "currencyCode" => "USD",
           "cancelUrl" => root_path,
           "returnUrl" => root_path,
           "requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
@xml = XmlSimple.xml_in(res.content)
payKey = @xml["payKey"].to_s()
payKey = payKey.tr("[]", "")
payKey = payKey[1..20]
redirect_to "https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=#{payKey}"
 end

and I get error:

      undefined local variable or method `root_path'

Why I can’t use this method ? And why I can’t use redirect_to ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:08:19+00:00Added an answer on June 8, 2026 at 3:08 am

    I don’t think root_path or root_url is available by default from within a model class. This is by design, since your model should not have knowledge of the controller/view/session-like operations. You can get access to the root_url by including this in the model though:

    include Rails.application.routes.url_helpers
    

    A better solution would be to pass this information into the order.pay method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has me stumped. I need to call an activity method from within
I need to call a method and pass an object from my custom UITableViewClass
I need to call a method I have defined as: -(IBAction)next:(id)sender{ ... } I
I have several models that need to call a method that takes a particular
This is hopefully a softball syntax question: I need to call a method with
I need a help from ur side. Actually I need to call a method
I am creating a Console Application, in that I need to Call a Method,
i need to log each method call in my application. i dont want to
I am using postsharp to log method call and i need to log the
I have a use case where I need to call a (non-static) method in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.