草庐IT

passing-data-between-view-control

全部标签

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

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

ruby-on-rails - rails 迁移 : How to increase column data type size by using ROR migration

我的用户表登录列是String类型,限制为40个字符。现在我打算将限制增加到55个字符。任何人请让我知道我们如何通过使用ROR迁移来增加此限制。谢谢,沙湾 最佳答案 classYourMigration55enddefdownchange_column:users,:login,:string,:limit=>40endend 关于ruby-on-rails-rails迁移:HowtoincreasecolumndatatypesizebyusingRORmigration,我们在Sta

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 - 相当于 Ruby 中的 “pass”

在python中有一个pass关键字用于定义空函数、条件、循环...Ruby有类似的东西吗?Python示例:defsome_function():#donothingpass 最佳答案 不,Ruby中没有这样的东西。如果你想要一个空block、方法、模块、类等,只需写一个空block:defsome_methodend就是这样。在Python中,要求每个block都包含至少一个语句,这就是为什么您需要一个“假的”空操作语句。Ruby没有语句,它只有表达式,而且block中包含零个表达式是完全合法的。

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 模板 : How to pass variables into inlined ERB?

我有一个内联到Ruby代码中的ERB模板:require'erb'DATA={:a=>"HELLO",:b=>"WORLD",}template=ERB.newcurrentvalueis:EOFDATA.keys.eachdo|current|result=template.resultoutputFile=File.new(current.to_s,File::CREAT|File::TRUNC|File::RDWR)outputFile.write(result)outputFile.closeend我无法将变量“current”传递到模板中。错误是:(erb):1:undefi

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