show_me
テンプレートをレンダリングするときに、モデルのさまざまなクラス(ちょっとウィジェット)内で定義されたメソッドを呼び出す単純なテンプレートシステムがあります。これらのウィジェットは元々、htmlを文字列として返しました。だから私のエルブでは、私はこのようなことを考えています。
<% @template.widgets.each do |widget| %>
<%= widget.show_me %>
<% end %>
ウィジェットのビューがより複雑になるにつれて、ActionView::Base
ウィジェット内からrenderメソッドを呼び出して、パーシャルを使用してウィジェットをレンダリングし始めます(まだスローしないでください:)
def show_me
# ... specific calculations and other magic.
ActionView::Base.new(MyApp::Application.config.view_path).render(:partial => "widgets/weather_widget", :locals => {:data => data, :settings => settings})
end
したがって、これは魅力のように機能しますが(実際には...)、ウィジェット固有のパーシャル(たとえば)内でヘルパーを使用したい場合widgets/_weater_widget.html.erb
は機能しません。例えば。javascript_tag
上げる
can't convert nil into String
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:790:in `join'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:790:in `rails_asset_id'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:813:in `rewrite_asset_path'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:742:in `compute_public_path'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:256:in `javascript_path'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:822:in `javascript_src_tag'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:362:in `block in javascript_include_tag'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:362:in `collect'
actionpack (3.0.0) lib/action_view/helpers/asset_tag_helper.rb:362:in `javascript_include_tag'
ActionView :: Baseを作成するときに、何かが足りないと思います。
これを解決する方法について何か考えはありますか?また、全体的なデザインに関する提案も歓迎します:)