Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, use the content of file in the controller

I've a file in the config directory, let's say my_policy.txt. I want to use the content of that file in my controller like a simple string.

@policy = #content of /config/my_policy.txt

How to achieve that goal, does Rails provide its own way to do that?

Thanks

like image 411
denisjacquemin Avatar asked Dec 12 '22 22:12

denisjacquemin


1 Answers

Rails doesn't provide a way, but Ruby does:

@policy = IO.read("#{Rails.root}\config\my_policy.txt")
like image 119
John Topley Avatar answered Dec 29 '22 20:12

John Topley