默认对象属性不默认为HTML
问题描述:
if @challenge.name == 'foo'
@challenge.category = 'habit'
@challenge.days_challenged = 21
@challenge.why = 'bar'
else
:days_challenged
& :why
正确的_form为foo
被设置但不:category
。默认对象属性不默认为HTML
<div class="challenge-category">
<input class="date-format-switcher" type="radio" value="goal" name="challenge[category]" id="challenge_category_goal">
<label for="challenge_category_goal">Goal</label>
<input class="date-format-switcher" type="radio" value="habit" name="challenge[category]" id="challenge_category_habit">
<label for="challenge_category_habit">Habit</label>
</div>
<%= f.number_field :days_challenged, class: 'day-challenge' %>
<%= f.text_area :why %>
答
我假设你有目的地为你的单选按钮定制编码。所选择的单选按钮应具备的属性“选中”,即
<input class="date-format-switcher" type="radio" value="habit"
name="challenge[category]" id="challenge_category_habit" checked />
动态设置:
<%= f.radio_button :category, 'goal', class: 'date-format-switcher' %>
<%= f.radio_button :category, 'habit', class: 'date-format-switcher' %>
快,让你的控制器的方法,并查看完整的代码 – Ilya