开发者

Rails 3 view partial passing a block

开发者 https://www.devze.com 2023-02-05 16:56 出处:网络
I\'d like to create a partial as follow: %nav.tab_nav %ul %li.active %a Variable1 %li %a Variable2 %li %a Variable...n

I'd like to create a partial as follow:


%nav.tab_nav
  %ul
    %li.active
          %a
            Variable1
        %li
          %a
            Variable2
        %li
          %a
            Variable...n

Where variable1 variable2 etc exist, but the number of variables change, so I could traverse an array of arguments or something, but I don't know how to pass this array to the partial. Is there a wa开发者_Python百科y to pass a block or similar ?


Passing locals for partial:

= render :partial => "tabs", :locals => { :items => ["foo", "bar", "baz"] }

Looping part:

%nav
  %ul
    - items.each do |item|
      %li
        %a= item

http://guides.rubyonrails.org/layouts_and_rendering.html#passing-local-variables

0

精彩评论

暂无评论...
验证码 换一张
取 消