ruby on rails - Default object attribute not defaulting for HTML -
if @challenge.name == 'foo' @challenge.category = 'habit' @challenge.days_challenged = 21 @challenge.why = 'bar' else
:days_challenged
& :why
being set in _form foo
not :category
.
<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 %>
i assume purposefully custom-coding radio buttons. selected radio button should have attribute "checked", i.e.
<input class="date-format-switcher" type="radio" value="habit" name="challenge[category]" id="challenge_category_habit" checked />
to set dynamically:
<%= f.radio_button :category, 'goal', class: 'date-format-switcher' %> <%= f.radio_button :category, 'habit', class: 'date-format-switcher' %>
Comments
Post a Comment