小编Alo*_*and的帖子

Rails Ruby键的哈希值由键合并为平均值

我有一个activerecord方法,可以查找本周的所有事件, myevents.map { |x| x.start_date.day => [x.title]} (start_date是一个日期时间字段,标题是一个字符串),它给了我一个哈希数组;

    [{11=>["40"]}, {11=>["0"]}, {11=>["0"]}, {11=>[""]}, 
     {11=>["0"]}, {11=>["0"]}, {11=>["33"]}, {12=>["9"]}, 
     {11=>["34"]}, {11=>["29"]}, {11=>["8"]}, {11=>["31"]}, 
     {11=>["40"]}, {11=>["34"]}] 
Run Code Online (Sandbox Code Playgroud)

我想映射值,所以我得到一个看起来像的数组;

[ {11=>[ average of values that occur on the 11th]}, 
  {12=>[average of values that occur on the 12th]} ]
Run Code Online (Sandbox Code Playgroud)

但我不太清楚如何得到它.

ruby arrays hash ruby-on-rails

4
推荐指数
1
解决办法
1301
查看次数

如何从html.erb调用JavaScript函数

如何从html.erb调用JavaScript函数

application.js中

function displayClock() {
  var digital = new Date();
  var hours = digital.getHours();
  var minutes = digital.getMinutes();
  var seconds = digital.getSeconds();
  var amOrPm = 'AM';
  if (hours > 11) amOrPm = 'PM';
  if (hours > 12) hours = hours - 12;
  if (hours == 0) hours = 12;
  if (minutes <= 9) minutes = '0' + minutes;
  if (seconds <= 9) seconds = '0' + seconds;
  dispTime = '<b>'+hours + ':' + minutes + ':' + seconds + …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

4
推荐指数
1
解决办法
9886
查看次数

语法错误,意外的tCONSTANT

谁能解释一下我的问题是什么:

ActiveRecord::Base.connection.select_values('SELECT c.value FROM custom_values c,
time_entries p, custom_fields cf  where  c.customized_type = 'TimeEntry' 
and p.id = c.customized_id and c.custom_field_id = cf.id 
and cf.type = 'TimeEntryCustomField' and cf.name = 'Reference TS Client' 
and p.id = '+ log.user.id.to_s +' ;')
Run Code Online (Sandbox Code Playgroud)

我只是为"c.customized_type"得到了这个错误.可能是什么问题?

ruby ruby-on-rails ruby-on-rails-3

0
推荐指数
1
解决办法
1755
查看次数

标签 统计

ruby ×3

ruby-on-rails ×3

arrays ×1

hash ×1

ruby-on-rails-3 ×1