1

私は自分のルールファイルにこれを持っています:

compile '/gallery/' do  
  filter :haml
  layout :'gallery'
end  
...
compile '/' do  
  filter :haml
  layout :'default'
end  
...
route '/gallery/' do  
  nil
end
...
route '*' do  
  item.identifier.chop + '.' +item[:extension]
end

、したがって、私の content/index.html は Haml フィルターを通過し、output/index.html としてコンパイルされます。私の content/gallery.html には、haml も通過する次のコードが含まれています。

#gallery-container  

%ul.items-small  
  %li.item  
    - @item.children.each do |img|  
      %a{:href => "#{img.path}"}  

%ul.items-big  
  %li.item-big  
    - @item.children.each do |img|  
      %a{:href => "#"}  
        %figure  
          %img{:src => "#{img.path(:rep => :thumbnail)}"}  
          %figcaption.img-caption Caption  

content/gallery/、それはフォルダー内のいくつかの画像を収集し、ルーティングを設定するとoutput/gallery/index.html(プレビュー出力が吐き出されるのを確認するために)、必要なものが得られるので、すべてうまくいきます。

content/index.htmlしかし今、私はその生成されたコードを=render 'gallery'私の. 次に、エラーメッセージが表示されますLocalJumpError: no block given (yield)

私のファイルには何があるべきです かlayouts/gallery.html?, そこに置く<%= yield %>と上記のエラーが発生します, 削除して=render 'gallery'もエラーはありません.エラーなしで含まれます。では、想定しているギャラリー コードを <%= yield %> し、index.html から =render 'gallery' を呼び出す必要がありますか?? しかし、それはうまくいきません。また、それはすでに機能している独自の利回りを持っているので、その利回りを介してコンパイルされる項目でその =render を使用しようとします。私はそれを間違った方法でやっていますか?迷っています!
layouts/gallery.html=render 'gallery'layouts/gallery.htmllayouts/gallery.htmllayouts/default.html

私のレイアウトファイルはすべて:erbフィルタリングされています。

したがって、私の質問は、このパーシャルをどのように含めるかです。ありがとう!

4

2 に答える 2

1

試行錯誤した後、このようにすべきだと思われますが、

= items["/gallery/"].compiled_content

content/index.html.haml代わりにそれをファイルに入れると、期待どおりの結果が得られ、content/gallery.html.hamlその場所にレンダリングされます。どこrenderでパーシャルを使用するのか、ここで使用したものとこれを使用することの違いは何ですか。

于 2014-01-03T09:38:55.573 に答える