Basically, I have a class that outputs some html:
class Foo
  include ActionView::Helpers
  def initialize(stuff)
    @stuff = s开发者_JS百科tuff
  end
  def bar
    content_tag :p, @stuff
  end
end
so I can do: Foo.new(123).bar
and get "<p>123</p>"
... But what I really want to do is something like this:
class Foo << ActionView::Base
  def initialize(stuff)
    @stuff = stuff
  end
  def bar
    render :template => "#{Rails.root/views/foo/omg.html.erb}"
  end
end
# views/omg.html.erb
<h1>Wow, stuff is <%= @stuff %></h1>
and then do Foo.new(456).bar and get "<h1>Wow, stuff is 456</h1>"
Just call erb directly? Something like:
def bar
  template = ERB.new(File.read("#{Rails.root}/views/foo/omg.html.erb"))
  template.result(binding)
end
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论