jjzjj

controllers

全部标签

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上找到

ruby-on-rails - 如何更改 Rails 3 Controller 中 View 文件的默认路径?

我有一个名为ProjectsController的Controller。默认情况下,它的操作在app/views/projects中查找View。我想更改所有方法的路径(index、show、new、edit等。.)在Controller中。例如:classProjectsController请注意,我并没有用render更改每个方法,而是为所有这些方法定义了一个默认路径。这可能吗?如果是,怎么办?谢谢! 最佳答案 参见ActionView::ViewPaths::ClassMethods#prepend_view_path.cla

ruby-on-rails - Rails 5 API Controller 中未定义的实例方法 "respond_to"

在用--api创建的rails5中我有一个错误NoMethodError(undefinedmethod`respond_to'for#Didyoumean?respond_to?):然而,在rails4.2的文档中它说http://edgeguides.rubyonrails.org/4_2_release_notes.htmlrespond_withandthecorrespondingclass-levelrespond_tohavebeenmovedtotherespondersgem.Addgem'responders','~>2.0'toyourGemfiletouseit

ruby-on-rails - 将 POST 数据从 Controller 提交到 Rails 中的另一个网站

用户提交包含一些基本数据的表单。数据由Controller中的操作接收和处理,并添加更多需要保密的信息。然后我需要向外部网站发送一个post请求,其中包含来自Controller的所有组合数据。执行此操作的最佳方法是什么? 最佳答案 最简单的方法是使用ruby​​核心库:require"uri"require"net/http"params={'box1'=>'Nothingislessimportantthanwhichforkyouuse.Etiquetteisthescienceofliving.Itembracesevery

ruby-on-rails - Controller 规范未知关键字 : id

我有简单的Action表演defshow@field=Field.find_by(params[:id])end我想为它写规范require'spec_helper'RSpec.describeFieldsController,type::controllerdolet(:field){create(:field)}it'shouldshowfield'doget:show,id:fieldexpect(response.status).toeq(200)endend但是我有一个错误Failure/Error:get:show,id:fieldArgumentError:unknown

ruby-on-rails - 如何在 Rails Controller 中返回 HTTP 204

这看起来很基础,但我是Ruby/Rails初学者。我只需要在Controller中返回HTTP204。会respond_todo|format|format.htmlend返回204? 最佳答案 head:no_content使用Rails3.2.x、4.x测试。它会导致Controller方法以204NoContentHTTP状态代码进行响应。在名为foobar的Controller方法中使用它的示例:deffoobarhead:no_contentend 关于ruby-on-rail

ruby-on-rails - 我们可以从 View 调用 Controller 的方法吗(理想情况下我们从 helper 调用)?

在RailsMVC中,您能否从View中调用Controller的方法(因为方法可以从助手中调用)?如果是,如何? 最佳答案 这里是答案:classMyController然后,在您看来,您可以在ERB中引用它,完全符合您对的期望。或: 关于ruby-on-rails-我们可以从View调用Controller的方法吗(理想情况下我们从helper调用)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co