我创建了一个辅助方法来动态地更改表中某些行的背景颜色:我的html如下所示:
<% @treatments.each do |f| %>
<tr class="<%= category_table_row_class(f.category) %>">
.....
Run Code Online (Sandbox Code Playgroud)
和我的助手方法:
module ApplicationHelper
def category_table_row_class(category)
{ 0 => "success", 1 => "warning", 2 => "error", 3 => "info" }[category.id]
end
end
Run Code Online (Sandbox Code Playgroud)
但我有一些问题,我得到错误:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Run Code Online (Sandbox Code Playgroud)
我希望有人可以帮助我吗?谢谢
我有一个Rails应用程序,我尝试将代码写入字符串:
<% @diagnoses.each do |f| %>
<a href="#" data-dropdown="drop#{f.id}" class=" tiny button dropdown expand">"#{f.beschreibung}"</a><br>
Run Code Online (Sandbox Code Playgroud)
但不知何故,"drop#{f.id}"并"#{f.beschreibung}"没有把它写成变量.我做错了什么,为什么?
我想检查设置表中是否存在id为2的条目,如果不存在,我想要将用户重定向到setting_new_path.我的代码看起来像这样:
def index
if Setting.find(2).present?
@patients = Patient.all
@patients_drucken = Patient.drucken
@anrede = Setting.find(1).anrede
respond_to do |format|
format.html # index.html.erb
format.json { render json: @patients }
end
else
redirect_to new_setting_path
end
end
Run Code Online (Sandbox Code Playgroud)
但不知怎的,我得到了错误:
Couldn't find Setting with id=2
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这显示为错误!我的意思是在它没有定义的情况下,重定向到new_setting_path!是什么让我错了?
我有这个代码,以获得数组中的最高和最低值,然后打印出七行中的所有值:
int hochstes;
int niedrig;
int q = 0;
for(int i = 1; i <= 49; i++){
if(hochstes == null){
hochstes = array[i];
niedrig = hochstes;
}
if(array[i] > hochstes){
hochstes = array[i];
}
if(array[i] < niedrig){
niedrig = array[i];
}
q++;
if(q == 7){
q = 0;
System.out.println("");
}else{
String a = (i < 10) ? " " + i : "" + i;
System.out.print(a + ": " + array[i] + " ");
}
}
Run Code Online (Sandbox Code Playgroud)
在第4行我试图检查是否hochstes有一个值,如果没有我分配数组的第一个("第二")值!当然,它不会hochstes …
我试图<a>用jquery 旋转一个简单的元素:
<a href="#" id="optbut2" style="margin-right: 8px;">
Run Code Online (Sandbox Code Playgroud)
此元素位于列表中:
<li class="list-group-item"><a href="#" id="optbut2" style="margin-right: 8px;">V</a><a href="#">Motorola</a></li>
Run Code Online (Sandbox Code Playgroud)
由于我使用Chrome我试过:
$('#optbut2').css('-webkit-transform','rotate(20deg)');
Run Code Online (Sandbox Code Playgroud)
但不知怎的,它不会工作!我错了什么?这是一个演示:http://jsfiddle.net/52VtD/6059/
我正在使用分页和jQuery,我的代码首先看起来像这样:
$(function() {
$(".pagination a").live("click", function() {
$.get(this.href, null, null, "script");
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
然后我注意到live在jQuery 1.9中删除了所以我将代码更改为:
$(function() {
$(".pagination").on("click", 'a', function() {
$.get(this.href, null, null, "script");
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
但不知怎的,这也行不通!问题是我可以从第一个ajax页面导航到第二个页面,然后将第二个页面导回到第一个页面或第三个页面,我的ajax不起作用.我太习惯了,因为我的代码没有注意到新添加的内容.pagination a.
我尝试在java中获取当前时间和小时:
import java.util.Calendar;
import java.util.Date;
public class Clock2
{
// instance variables - replace the example below with your own
private int minute;
private int hour;
private String daytime;
/**
* Constructor for objects of class Clock2
*/
public Clock2()
{
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
this.hour = Calendar.HOUR_OF_DAY;
this.minute = Calendar.MINUTE;
}
Run Code Online (Sandbox Code Playgroud)
但不知怎的,现在13.33我得到一小时11一分钟12我错了什么?谢谢