简体   繁体   中英

How to call controller action and then render it to a string in ror?

How to call controller action and then render in to a string from "outside" in ror?

class SomeService
  controller = UsersController.new
  # need to call an index action
  # data = controller.render_to_string 
end

If you can, try this with the new Rails 5 , where rendering views from outside controllers is possible and supported . Rails 5 is currently in beta, so in a few weeks it should be released officially .

I have no idea how to achieve a similar thing in earlier Rails versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM