草庐IT

remote-control

全部标签

ruby-on-rails - rails : How to determine controller/action in view

这是我的部分表格:{:multipart=>true}do|d|%>'Uploadlogo',:required=>false%>'Image,:required=>false',:style=>'margin-bottom:2px'%>'BilledURL',:required=>false%>如果操作是编辑,我想改为显示:{:multipart=>true}do|d|%>'Uploadlogo',:required=>false%>'Image,:required=>false',:style=>'margin-bottom:2px'%>'BilledURL',:required=

ruby-on-rails - 分析 Rails Controller 操作

在RubyonRails中分析Controller操作的最佳方法是什么。目前,我正在使用蛮力方法,在我认为会成为瓶颈的部分之间插入putsTime.now调用。但这感觉真的非常脏。一定有更好的方法。 最佳答案 我不久前学习了这项技术,发现它非常方便。当它就位时,您可以将?profile=true添加到任何访问Controller的URL。您的操作将照常运行,但它不会将呈现的页面传送到浏览器,而是发送一个详细的、格式良好的ruby​​-prof页面,显示您的操作花费时间的地方。首先,将ruby​​-prof添加到你的Gemfile中,

ruby-on-rails - 为什么 Ruby open-uri open 在我的单元测试中返回一个 StringIO,而在我的 Controller 中返回一个 FileIO?

我继承了一个Rails2.2.2应用程序,它在AmazonS3上存储用户上传的图像。基于attachment_fu的Photo模型提供了一个rotate方法,该方法使用open-uri从S3和MiniMagick中检索图像以执行旋转。rotate方法包含这一行来检索用于MiniMagick的图像:temp_image=MiniMagick::Image.from_file(open(self.public_filename).path)self.public_filename返回类似的内容http://s3.amazonaws.com/bucketname/photos/98/phot

ruby-on-rails - Rails before_filter 用于 Controller 中的特定操作

defnewbefore_filterdoredirect_to"/"unlesscurrent_admin||current_companyflash[:notice]='Youdonthaveenoughpermissionstobehere'unlesscurrent_admin||current_companyendCODECODECODEenddefeditbefore_filterdoredirect_to"/"unlesscurrent_admin.id=5flash[:notice]='Youdonthaveenoughpermissionstobehere'unles

ruby - 如何使用 RSpec 在 Controller 中实例化实例变量

我正在尝试检查我的RESTfulController中的新操作是否设置了所需对象类型的实例变量。看起来很典型,但执行起来有问题客户端Controllerdefnew@client=Client.newend测试describe"GET'new'"doit"shouldbesuccessful"doget'new'response.shouldbe_successendit"shouldcreateanewclient"doget'new'assigns(:client).should==Client.newendend结果......'ClientsControllerGET'new'

ruby-on-rails - 向现有 Controller 添加操作 (Ruby on Rails)

我是RubyonRails的新手,我已经完成了BlogTutorial.我现在正尝试向Controller添加一个额外的操作,称为“开始”。defstartend我添加了一个View页面“app/views/posts/start.html.erb”,只包含简单的html。当我转到/posts/start时,出现以下错误。ActiveRecord::RecordNotFoundinPostsController#showCouldn'tfindPostwithID=start我了解错误,正在执行显示操作并且开始不是有效ID。为什么启动操作没有执行,是否缺少MVC架构或配置的某些部分?下

ruby-on-rails - 过滤器在渲染之前但在 Controller 之后执行?

假设我在基本Controller中有一些逻辑将信息传递给View以构建类似面包屑的东西:classContextAwareController我希望此build_breadcrumb方法在主Controller逻辑之后但View呈现之前运行。上面的代码运行得太晚了,但是before_filter就太早了。有人可以建议一种方法来完成此操作,而无需在子Controller中的每个操作结束时显式调用build_breadcumb吗?谢谢 最佳答案 我遇到了同样的问题,然后这样解决了:classApplicationController

ruby - Action Controller ::未知格式

在我的Rails应用程序中,我向服务器发出了一个ajax请求,以存储一些数据。这曾经没有任何问题,但现在我得到一个错误:ActionController::UnknownFormat(ActionController::UnknownFormat):app/controllers/reservations_controller.rb:45:in`create'如下是Controller和我声明数据类型为JSON的javascript文件classReservationController函数.js$.ajax({url:url_link,dataType:'json',type:'PO

ruby-on-rails - 如何使用 Rails 3 获取请求的目标 Controller 和操作?

在过滤器之前的应用程序Controller中。classApplicationController 最佳答案 classApplicationController 关于ruby-on-rails-如何使用Rails3获取请求的目标Controller和操作?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5418454/

ruby-on-rails - 如何为 Rails Controller 添加延迟以进行测试?

我正在测试Web应用程序的前端,并想测试在AJAX请求之间的各种延迟下,某些转换是如何出现的。有什么方法可以向我的Controller添加sleep(1500)以延迟响应? 最佳答案 Controller是这样的:defcatalog#Makestherequestpause1.5secondssleep1.5...end更好的是:只为开发环境添加sleep。 关于ruby-on-rails-如何为RailsController添加延迟以进行测试?,我们在StackOverflow上找到