要调用帮助程序,请使用以下helper对象:$ ./script/console>> helper.number_to_currency('123.45')=> "R$ 123,45"如果您想使用默认情况下未包含的帮助程序(例如,因为您已helper :all从中删除ApplicationController),只需包含帮助程序即可。>> include BogusHelper>> helper.bogus=> "bogus output"至于处理控制器,我引用尼克的回答:> app.get '/posts/1'> response = app.response# you now have a rails response object much like the integration tests> response.body # get you the HTML> response.cookies # hash of the cookies# etc, etc
从脚本/控制台调用控制器操作并查看/操作响应对象的简单方法是:> app.get '/posts/1'> response = app.response# you now have a rails response object much like the integration tests> response.body # get you the HTML> response.cookies # hash of the cookies# etc, etcapp对象是ActionController :: Integration :: Session的一个实例这适用于我使用Rails 2.1和2.3,我没有尝试早期版本。