Ruby on Rails
Monday, December 1, 2014
Each / Each with index returns the same array . You need to use map.
<%= select "obj", "test", @timeslots.map.with_index{ |name, index| [name, index] } %>
On Mon, Dec 1, 2014 at 3:58 PM, Dmoneyzzz Darko <lists@ruby-forum.com> wrote:
Hello,
I have created an array of time slots as strings and am trying to
display them in a form to be selected upon creation.
This is my Appointments controller file.
helper_method :timeslots
def timeslots
@timeslots = ['8:30 AM','9:00 AM','9:30 AM','10:00 AM','10:30
AM','11:00 AM','11:30 AM', '12:00 PM', '12:30 PM', '1:00 PM','1:30 PM',
'2:00 PM', '2:30 PM', '3:00 PM', '3:30 PM','4:00 PM']
end
This is my Appointments form.html.erb file
<div class="field">
<%= f.label :appointment_time %><br>
<%= select "obj", "test", timeslots.each_with_index.map { |name,
index|} %>
</div>
On the form's page, I just see a blank box with no values. Every time I
add a value, the box gets bigger, but there are no values displayed in
the rows of the select box.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/36cd092d0b998ea2fbfeb853886c4c3e%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj_1toJy3Jd30ea0AgCLfN%2B9Pdob3YfjQU_Lm%2BNqWp5Wxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment