我正在实现current_page?一个视图来测试当前控制器和动作是否等于某个值,但是当在该控制器/动作组合上时它不会返回true.
- if current_page?(:controller => 'pages', :action => 'main')
# doesn't return true when on that controller/action combination
Run Code Online (Sandbox Code Playgroud)
它工作的唯一方法是如果我使用更详细的方法,如下所示:
- if controller.controller_name == 'pages' && controller.action_name == 'main'
# this works just fine
Run Code Online (Sandbox Code Playgroud)
我的语法错了还是在这里发生了其他事情?有没有更好的方法来做到这一点,比如设置BOOL或者这是正确的方法吗?
最终目标是仅在主着陆页上显示某个标题,同时在所有其他页面上显示不同的标题.
编辑:相关输出来自rake routes:
pages_main GET /pages/main(.:format) {:controller=>"pages", :action=>"main"}
root /(.:format) {:controller=>"pages", :action=>"main"}
Run Code Online (Sandbox Code Playgroud)
此外,这是渲染时的服务器输出:
Started GET "/" for 127.0.0.1 at 2011-03-03 16:54:40 -0500
Processing by PagesController#main as HTML
Rendered pages/main.html.haml within layouts/application (203.8ms)
Run Code Online (Sandbox Code Playgroud) <%= Math.Round(netValue)%>
Run Code Online (Sandbox Code Playgroud)
它输出的一个例子可能是-1243313
如何确保将其格式化为美国货币(使用'$',正确的逗号等)?
可能重复:
在终止进程之前保存gmon.out
我正在尝试在Linux环境中分析服务器(可用的源代码.c代码).该服务器像Web服务器一样连续运行.我正在尝试使用gprof来配置服务器.如果服务器自行退出,则会生成gmon.out文件.我可以使用gprof和gmon.out来理解配置文件数据.现在问题是,这台服务器正在连续运行,等待传入的套接字连接,请求等.如果我终止此服务器,则不会生成gmon.out.此时我看到以下选项.
编辑:服务器是多进程服务器.在FreeBSD 7.2上运行
我敢肯定,人们之前已经解决了这些问题.我没能在SO或外面找到有用的信息.
我感谢人们的任何想法/解决方案.
谢谢一堆.
更新1:
不知怎的,我设法为valgrind获得端口.当我运行make时,我得到以下错误.
=> valgrind-stable-352.tar.gz doesn't seem to exist in /usr/obj/ports/distfiles/.
=> Attempting to fetch from ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/.
fetch: ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/valgrind-stable-352.tar.gz: File unavailable (e.g., file not found, no access)
=> Attempting to fetch from http://www.rabson.org/.
fetch: http://www.rabson.org/valgrind-stable-352.tar.gz: No address record
=> Couldn't fetch it - please try to retrieve this
=> port manually into /usr/obj/ports/distfiles/ and try again.
*** Error code 1
Run Code Online (Sandbox Code Playgroud)
我试图在网上找到valgrind-stable-352.tar.gz.我找到的所有链接都已死亡.
我在我的freebsd上安装了pstack,实现的pstack只提供堆栈跟踪.参考:http://sourceforge.net/projects/bsd-pstack/
我的理解是systemtap仅用于内核空间事件,仪器等. …
我试图将一条线分成多个部分.因为我在下面创建了一个函数来尝试获得两点之间的子点.它不是很有效,但几乎就在那里.理想情况下,我想使用这样的东西:
subPoint(point1, point2, 5, 10); // this would return the half way point
subPoint(point1, point2, 1, 10); // this would return a point 1 tenth towrds point2
Run Code Online (Sandbox Code Playgroud)
以下是粗略的代码 - 非常欢迎任何提示或指示.
Vector subPoint(Vector startPoint, Vector endPoint, int segment, int totalSegments) {
int division = (int)(totalSegments / segment);
PVector divPoint = new PVector();
int midX=(int)(startPoint.x+((endPoint.x-startPoint.x)/division));
int midY=(int)(startPoint.y+((endPoint.y-startPoint.y)/division));
divPoint.set(midX, midY, 0);
return(divPoint);
}
Run Code Online (Sandbox Code Playgroud) 我想使用jQuery异步加载文档的CSS.
我找到了这个示例,但这似乎在IE中不起作用:
<script type="text/javascript" src="/inc/body/jquery/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(function(){
$('<link>', {
rel: 'stylesheet',
type: 'text/css',
href: '/inc/body/jquery/css/start/jquery-ui-1.8.10.custom.css'
}).appendTo('head');
$.getScript("/inc/body/jquery/js/jquery-ui-1.8.10.custom.min.js", function(){
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
基本上我想加载jQuery UI所有其他数据,图像,样式等加载到页面.
这个$.getScript作品非常适合JS文件.唯一的问题是IE中的CSS.
你知道更好的解决方案吗?
我有以下代码在iPhone应用程序中工作正常但在iPad中我总是得到灰色/浅蓝色背景颜色.即使我改变背景颜色也不会生效.
[self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1024x768.png"]]];
Run Code Online (Sandbox Code Playgroud)
谢谢
我在python脚本中使用ctypes lib时遇到了麻烦.这是我的代码(在互联网上找到):
if __name__ == "__main__":
from ctypes import *
user32 = windll.user32
kernel32 = windll.kernel32
class RECT(Structure):
_fields_ = [
("left", c_ulong),
("top", c_ulong),
("right", c_ulong),
("bottom", c_ulong)];
class GUITHREADINFO(Structure):
_fields_ = [
("cbSize", c_ulong),
("flags", c_ulong),
("hwndActive", c_ulong),
("hwndFocus", c_ulong),
("hwndCapture", c_ulong),
("hwndMenuOwner", c_ulong),
("hwndMoveSize", c_ulong),
("hwndCaret", c_ulong),
("rcCaret", RECT)
]
def moveCursorInCurrentWindow(x, y):
# Find the focussed window.
guiThreadInfo = GUITHREADINFO(cbSize=sizeof(GUITHREADINFO))
user32.GetGUIThreadInfo(0, byref(guiThreadInfo))
focussedWindow = guiThreadInfo.hwndFocus
# Find the screen position of the window.
windowRect = RECT() …Run Code Online (Sandbox Code Playgroud) 我使用名为library的数据库的mysqldump实用程序创建了一个名为ab.sql的文件.它工作正常.现在我正在尝试使用mysqlimport恢复它.我的数据库已存在.但我想覆盖它.我正在使用该命令
mysqlimport -uroot -p**** library D:/ab.sql
Run Code Online (Sandbox Code Playgroud)
在命令行中但是它给出了一个错误,
mysqlimport:错误:1146,当使用table:ab时,表'library.ab'不存在
迫切需要帮助.
我一直在使用SMS聚合器的web api来发送和接收短信.并非所有字符都有效,并且当我尝试发送带有哈希标记#的消息时,它会失败.
我需要在发送之前清理字符串,但是我找不到有效字符的有效列表.谷歌先生没有多大帮助 - 也许我正在寻找错误的条款.
我已经仔细检查了api手册,并通过电子邮件向公司发送了我的问题,但没有答案.
我希望不同的手机可以处理不同的字符列表...例如,iPhone应该可以处理各种各样的字符,但是我的旧诺基亚翻盖手机可能只处理字母数字之外的几十个字符.我需要最低的共同点.
我展示了MongoDB与SQL 2008的同事性能基准,虽然他认为MongoDB速度更快,但他并不了解它的可行性.他的逻辑是,SQL已经存在了几十年,并且有一些最聪明的人在研究它,以及MongoDB如何; 一个相对较新的孩子在性能上如此优越?我无法真正提供可靠和技术性的答案,我希望你们能提供帮助.