如果用户点击其中一个图标:
home.html.erb:
<span class="glyphicon glyphicon-picture", id="challenge-category"></span> #challenge.categorization: "adventure"
<span class="glyphicon glyphicon-heart", id="challenge-category"></span> #challenge.categorization: "health"
<span class="glyphicon glyphicon-briefcase", id="challenge-category"></span> #challenge.categorization: "work"
<span class="glyphicon glyphicon-shopping-cart", id="challenge-category"></span> #challenge.categorization: "buy"
<span class="glyphicon glyphicon-glass", id="challenge-category"></span> #challenge.categorization: "wacky"
如何仅显示共享点击categorization
的用户挑战?
分贝:
create_table "challenges", force: true do |t|
t.string "categorization"
end
challenge.rb:
CATEGORIZATION = ['adventure', 'health', 'work', 'buy', 'wacky']
scope :adventure, -> { where(categorizations: 'Adventure') }
scope :health, -> { where(categorizations: 'health') }
scope :work, -> { where(categorizations: 'Work') }
scope :buy, -> { where(categorizations: 'Buy') }
scope :wacky, -> { where(categorizations: 'Wacky') }
scope :goal, -> { where(categories: 'Goal') }
scope :habit, -> { where(categories: 'Habit') }
控制器:
def home
@challenges = current_user.challenges.order("deadline ASC")
@adventure_challenges = current_user.challenges.adventure.order("deadline ASC")
@health_challenges = current_user.challenges.health.order("deadline ASC")
@work_challenges = current_user.challenges.work.order("deadline ASC")
@buy_challenges = current_user.challenges.buy.order("deadline ASC")
@wacky_challenges = current_user.challenges.wacky.order("deadline ASC")
end
我将javascript / jquery作为标记包含在内,因为它是一种更优雅的解决方案,可以避免页面重新加载,但对于此问题而言则不是必需的。
如何重写home.html.erb,以便在单击一个glyphicon时页面将重新加载(或触发JavaScript),然后只会显示与glyphicon所代表的categorization
相同的挑战?