daniel
daniel

Reputation: 9835

Rails 3 view partial passing a block

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 way to pass a block or similar ?

Upvotes: 0

Views: 658

Answers (1)

Heikki
Heikki

Reputation: 15417

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

Upvotes: 1

Related Questions