Satchel
Satchel

Reputation: 16734

How can I turn this into a block using a %w array in Ruby?

I have to have a series of buttons with different values:

<p>
  <%= f.submit "Connected", :class => 'button' %> 
  <%= f.submit "Voicemail"%>
  <%= f.submit "Hangup"%>
  <%= f.submit "Not Interested" %> 
  <%= f.submit "Wrong Number" %>  
</p`> 

Looking at it it seems I could turn it into a do block and pass a %w array but don't know exactly how....? Thanks...

Upvotes: 0

Views: 112

Answers (2)

Spyros
Spyros

Reputation: 48636

Example that illustrates the point :

%w[Connected Voicemail].each do |item|
     <%= f.submit "#{item}" %>
end

Since this is Rails, don't put this directly in your view, but construct it in a helper.

Upvotes: 4

Andrei S
Andrei S

Reputation: 6516

you mean like this?

<% button_titles.each do |button_title| %>

   <%= f.submit button_title, :class => 'button' %>

<% end %>

Upvotes: 0

Related Questions