Title says it all. It's pretty easy from controllers - just using "view_context". But it doesn't work with models.
E.g ApplicationController.new.view_context.url_for yields in: "undefined method 'host' for nil:NilClass"
ActionView::Base.new(Rails.configuration.paths["app/views"].first).url_for doesn't work as well.
Can this be done without so much pain ?
P.S I need it for my Prawn gem! I wanted to generate the PDF from the model. And apart from generating the links inside of it - it is very successful!
Hope for your help! Thanks in advance!
Rails 5
include Rails.application.routes.url_helpers
url_for(myModelObject)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With