【发布时间】:2016-05-21 10:50:34
【问题描述】:
所以用户选择“运行”作为他的challenge。现在他应该可以在类别之间切换:oneshot 或 ongoing。
现在所有属性都显示了,但是如果用户单击“One-shot”,我如何只显示oneshot 属性:deadline,如果用户单击“,我如何只显示ongoing 属性”进行中”?
挑战/_form.html.erb
<%= form_for(@challenge) do |f| %>
<%= f.text_field :action %>
<% Challenge::CATEGORY.each do |c| %>
<%= label(c, c) %>:
<%= f.radio_button(:category, c, :class => "date-format-switcher") %>
<% end %>
<%= f.fields_for :category do |category| %>
<%= render 'category_fields', :f => category %>
<% end %>
<%= button_tag(type: 'submit', class: "btn") do %>
Save
<% end %>
<% end %>
挑战/_category_fields.html.erb
One-Shot
<%= f.date_select :deadline, :order => [:month, :day, :year], use_short_month: true, class: 'date-select' %>
Ongoing
<%= f.date_select :date_started, :order => [:month, :day, :year], :with_css_classes => true, :class => "date-select" %>
<%= f.collection_check_boxes :committed, Date::ABBR_DAYNAMES, :downcase, :to_s %>
<%= f.number_field :days_challenged, value: 30, class: 'day-challenge' %>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
challenge.rb
class Challenge < ActiveRecord::Base
scope :oneshot, -> { where(categories: 'One-Shot') }
scope :ongoing, -> { where(categories: 'Ongoing') }
CATEGORY = ['One-Shot', 'Ongoing']
end
【问题讨论】:
标签: javascript jquery ruby-on-rails ruby model-view-controller