2

I have an action, and I've defined it in the routes.rb

resources :statistics, only: [] do
  get 'group_report/:id', to: 'statistics#group_report', as: 'group_report'
end

Then in the method in the model, I want to return the full URL.

Thus, I wrote this method

root_url + group_report_statistics_path(id)

The result is "http://localhost:3000//statistics/group_report/DHo6qzUzYXw"

I thought it was a dirty way, and I need to handle the double slash as well.

Does Rails provide some useful method which I can get the full URL of the action directly?

rj487
  • 4,476
  • 6
  • 47
  • 88

2 Answers2

2

Rails provides path as well as url helpers for all the routes.

So if you use group_report_statistics_url(id), you will get the full URL.

See Path and URL Helpers on the Rails guides for detailed description.

IngoAlbers
  • 5,722
  • 6
  • 31
  • 45
0

try this

File.join(root_url + group_report_statistics_path(id))

or

 group_report_statistics_url(id)
Sachin R
  • 11,606
  • 10
  • 35
  • 40