开发者

What is causing this difference between my Ruby on Rails console output and my Firebug console output when using a Ruby date object?

Can anyone explain the difference between the Ruby on Rails console output and the Firebug console output?

event_controller.rb

def list_events
    @days[1][:date] = (((Date.new(2010, 8, 6)) + 1).to_s)
end

list_events.html.erb

<% @days.each_with_index do |day, i| %>
    <% p day[:date] %>; //RoR console
    console.log(<%= day[:date] %>); //Firebug con开发者_如何学Csole
<% end %>

Ruby on Rails console output:

"2010-08-07"

Firebug console output:

1995


The JavaScript statement that is actually being executed is this:

console.log(2010-08-07);

—This is evaluated as 2010 minus 8 minus 7, which equals...1995! You have to make sure that the console log statement receives a string. Try this instead:

console.log("<%= day[:date] %>");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜