我有一个模型可以从特定城市获取所有游戏.当我得到那些游戏时,我想过滤它们,我想使用这个reject方法,但是我遇到了一个我想要理解的错误.
# STEP 1 - Model
class Matches < ActiveRecord::Base
def self.total_losses(cities)
reject{ |a| cities.include?(a.winner) }.count
end
end
# STEP 2 - Controller
@games = Matches.find_matches_by("Toronto")
# GOOD! - Returns ActiveRecord::Relation
# STEP 3 - View
cities = ["Toronto", "NYC"]
@games.total_losses(cities)
# FAIL - undefined method reject for #<Class:0x00000101ee6360>
# STEP 3 - View
cities = ["Toronto", "NYC"]
@games.reject{ |a| cities.include?(a.winner) }.count
# PASSES - it returns a number.
Run Code Online (Sandbox Code Playgroud)
为什么reject在我的模型中失败但在我看来不是?
我想在模拟中存储有关人物对象的信用历史信息.
我想使用HashMap<Person, CreditHistory>,但java API说我应该警惕使用HashMaps跟踪可变对象(如信用历史,在我的程序中).
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/HashMap.html
这有更好的结构吗?
我使用以下编码来对齐底部的表格,但它无法正常工作
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body bgcolor="black">
<div class="footer">
<table border="1" bottom="0px">
<tr>
<td width="600px" align="right">
<input type="image" align="center" id="verify1" src="proceed1.png" disabled="disabled" width="90" height="90""/>
</td>
<td width="500px" align="right">
<label id = "l2" style = "color:white;font:normal 20px chalkdust;">NEXT QUESTION</label>
<div id="sample4" style="float: right;">
</td>
<td>
<input type="image" id="next" src="arrow.png" disabled="disabled" name="image2" width="80" height="80">
</td>
</tr>
</table>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助它在页面底部对齐.
有人可以帮我解决java中的以下问题.我有一个简单的类定义如下:
public class Expr {
public long total_apparitions;
public String expression=new String();
public Expr(long total,String expr){
this.total_apparitions=total;
this.expression=expr;
}
public void increment(long aparitions){
total_apparitions+=aparitions;
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用内置函数Expr按total_apparitions字段对对象数组进行排序Arrays.sort.如何为Arrays.sort函数指定比较因子?非常感谢.
需要使用PHP检查两个给定日期之间的给定日期,这是我写的代码:
$today = date_create('28-Feb-2012');
$fromdate = date_create('20-Feb-2012');
$todate = date_create('22-Feb-2012');
if ($today>=$fromdate && $todat<=$todate)
{
echo 'in range';
}
else
{
echo 'not in range';
}
Run Code Online (Sandbox Code Playgroud)
但这总是会回归in range.无法弄清问题在哪里.请帮忙.
如果模式匹配或执行另一个代码块(如果模式不匹配),我将如何执行代码块?
String input = "abc";
final String mainRegex = "(.*?)(&!|&|==)";
final Matcher matcher = Pattern.compile(mainRegex).matcher(input);
Run Code Online (Sandbox Code Playgroud)
我试过了
if(matcher1.matches())
{
execute this block
}
else
{
execute this block
}
Run Code Online (Sandbox Code Playgroud)
但它总是执行else块.即使输入是a>b&!c<d.
我想让我的整个div链接像a标签一样。当然这可能用 js 来实现,但我有兴趣看看这是否可以只用 css 来完成。
我有这个:
#my_div {
width: 200px;
background-color: #090;
}
#my_div:hover {
background-color: #0f0;
}
Run Code Online (Sandbox Code Playgroud)
页面结构在哪里:
<div id="my_div"><a href="http://google.com">link</a></div>
Run Code Online (Sandbox Code Playgroud) java ×3
css ×2
html ×2
activerecord ×1
arrays ×1
date ×1
enumeration ×1
php ×1
ruby ×1
sorting ×1