0

I'm using Rails 4.1.8 and I want to get the HTML output, as a string, from a certain controller inside a Helper which I'll later use in a View.

Assuming app were available at this point, this would be what I want. This, however, is just a conceptual example, not working code.

# pseudo-code
# widgets_helper.rb
module WidgetsHelper
  def widget_html(widget_id)
    app.get("/widgets/#{widget_id.to_s}.html")
    app.response.body
  end
end

I found this answer which appears to be related but I wasn't sure where to go with it.

I also read about render_to_string but I'm not sure if that's taking me to a workable solution either.

Update

That previous question has a comment that also mentions this question

Community
  • 1
  • 1
rb-
  • 2,315
  • 29
  • 41
  • 1
    The widgets are defined in your own rails app? If I understand correctly you should check out [cells](https://github.com/apotonick/cells). Or otherwise please give some example to clarify. – nathanvda Dec 24 '14 at 22:14
  • Yes it looks like by incorporating cells I should get the functionality I'm looking for. A Widget can render as HTML for the `widgets#show` action, but there's also a `widgets#embed` action that generates JavaScript within which I want to include the entire HTML output of `widget#show`. Cells looks like it can help me do that. – rb- Dec 24 '14 at 22:26
  • Or just use ajax to embed them? – nathanvda Dec 24 '14 at 22:34
  • 1
    I'm using Ajax now, but where I'm using it is loaded in script tag in the first place. So right now my embedded Widget makes 2 calls. I'm going to refactor a lot of my code into Cells and it will help me a ton. Thanks again for the suggestion. – rb- Dec 25 '14 at 17:57

0 Answers0