Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Engine RouteProxy outside View and Controller

I am trying to eval a routing helper string in a class that is designed for unsafe code evaluation. Basically I have a class SafeEval which will evaluate string in a sandboxed class. I did following to get route helpers working in SafeEval

include ActionController::UrlFor
include Rails.application.routes.url_helpers

All ruote helpers are working except engine route proxies. In my views and controllers I can call blog.page_path(@page) but I can't call blog.page_path in SafeEval - I get blog not defined. I checked in my view and blog is RouteProxy.

So my question is how can I get engine route proxy in a class outside view/controller

(SafeEvla does not do a lot of sandboxing. you can assume very simple structure: a method that just runs eval(str) for now inside a SafeEval class.)

like image 762
Iuri G. Avatar asked Dec 02 '25 14:12

Iuri G.


1 Answers

I think including the mounted helpers in your class would solve the problem:

include Rails.application.routes.mounted_helpers
like image 74
banhill Avatar answered Dec 04 '25 06:12

banhill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!