Reputation: 26071
I'm trying to create a select control with options using HAML in Sinatra. There should be an option for each value in my @ages array. I have verified that @ages is actually in the view by printing it out. My select tag however does not show these @ages.
%form
%label='Portfolio Type'
%select{name: :portfolio_type}
%option{value: :cash}='Cash'
%option{value: :securities}='Securities'
%br
%label='Current Age'
%select{name: :current_age }
- @ages.each do |age|
%option{:name => age, :value=> age}="#{age}"
%br
%label='Current Savings'
%input
%input
%input
below is the html that is being generated. I can see that the select tag is closing before the options.
<form>
<label>Portfolio Type</label>
<select name='portfolio_type'>
<option value='cash'>Cash</option>
<option value='future_advisor'>Future Advisor</option>
</select>
<br>
<label>Current Age</label>
<select name='current_age'></select>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
<option value='32'>32</option>
<option value='33'>33</option>
<option value='34'>34</option>
<option value='35'>35</option>
<option value='36'>36</option>
<option value='37'>37</option>
<option value='38'>38</option>
<option value='39'>39</option>
<option value='40'>40</option>
<option value='41'>41</option>
<option value='42'>42</option>
<option value='43'>43</option>
<option value='44'>44</option>
<option value='45'>45</option>
<option value='46'>46</option>
<option value='47'>47</option>
<option value='48'>48</option>
<option value='49'>49</option>
<option value='50'>50</option>
<br>
<label>Current Savings</label>
<input>
<input>
<input>
</form>
Upvotes: 1
Views: 932
Reputation: 499
As you noticed the select tag is closed before the options are listed.
That's Because you didn't indent the - @ages.each do |age|
statement.
Change this:
%select{name: :current_age }
- @ages.each do |age|
%option{:name => age, :value=> age}="#{age}"
To this:
%select{name: :current_age }
- @ages.each do |age|
%option{:name => age, :value=> age}="#{age}"
Upvotes: 4