Search code examples
ruby-on-railsrubydashing

request.original_url and undefined local variable or method `request' for main


I'm starting my adventure with ruby, and got stuck in one procedure I want to do so to the point, I'm using dashing to create some dashboards.

But I need a instruction to read my URL to get query parameters from it,

I was trying to use:

url = request.original_url
print(url)

But all Im getting is

'<top (required)>': undefined local variable or method 'request' for main:Object (NameError)

Am I missing something, maybe some gem or require?


Solution

  • You're trying to access the request method of controller, but you can't because you are in Model class at this point.

    Note: Update your code so it will be more clear. for your reference regarding request.original_url. You may want to read up on MVC in Rails or MVC in general.