【发布时间】:2016-11-03 05:23:37
【问题描述】:
型号
def previous_user_challenge_date_started
user.challenges.where('date_started >= ?', date_started).order('date_started ASC').first #date_started is a date, not datetime
end
有些挑战会有相同的date_started,这就是我想要>=的原因,但现在它会在点击link_to时一遍又一遍地重新加载当前的@challenge。
我怎样才能使用>=,但除了@challenge 是个例外,所以也许可以在模型方法中以某种方式使用not self?
查看
<%= link_to '← Previous', challenge_path(@challenge.previous_user_challenge_date_started), class: "prev" %>
控制器
@challenge = Challenge.find(params[:id])
【问题讨论】:
标签: ruby-on-rails ruby date model-view-controller methods