【发布时间】:2014-03-28 02:41:15
【问题描述】:
我创建了简单的交易网站。在 index.html.erb 循环中仅在第一个循环中工作。但它适用于 show.html.erb
<h1>Listing Deal</h1><% @projs.each do |proj| %>
<%= proj.title %><br />
<% if Time.now < proj.end_date %>
<h3>Days Left:</h3> <div id="countdown" style="width:40%"> <%= distance_of_time_in_words(Time.now, proj.end_date) %> </div>
<% else %>
<h3> The Project period has passed! </h3>
<% end %>
<script type="text/javascript">
$(document).ready(function(){
$('#countdown').countdown({
"until" : new Date(<%= date_for_jquery_countdown(proj.end_date) %>)
});
})
</script><% end %>
Projs_helper.rb**
def date_for_jquery_countdown(date)
year = date.strftime('%Y')
month = date.strftime('%-m')
day = date.strftime('%d')
"#{year}, #{month}-1, #{day}"
end
application.js
//= require jquery.plugin
//= require jquery.countdown
我的浏览器显示 index.html.erb 只显示第一个工作,但其他人不显示倒计时
【问题讨论】:
-
我的模型 def end_date self.start_date + self.funding_period.days end
标签: jquery ruby-on-rails ruby ruby-on-rails-3 for-loop