草庐IT

Controllers

全部标签

ruby-on-rails - rails : How can you access session variables using multiple controllers?

我在使用session变量时遇到问题。我有两个名为“graduate_students_controller”和“current_students_controller”的Controller。这些Controller中的每一个都控制不同的View文件。我在这两个Controller中使用session变量来存储session信息。问题来了。假设我有两个View文件“reports/current_students_list”、“reports/graduate_students_list”,每个文件都由上述Controller单独控制。现在,如果我尝试从同一浏览器中打开这两个网页并尝

ruby-on-rails - 使用 Rails 编写 RSpec 测试时,spec/requests 文件夹和 spec/controllers 应该放什么?

我对Rails还很陌生,并试图通过从一开始就实现测试来以“正确”的方式做事。昨天我使用脚手架生成器创建了我的第一个模型/View/Controller配置。虽然有人告诉我您真的不应该使用脚手架,但它很有用,因为我可以了解Rails代码的结构。我注意到的一件事是,自动生成的RSpec大部分放在spec/controllers文件夹中。然而当我看到thisepisodeofRailscasts,我注意到他用了railsgenerateintegration_test[test_name]将单个测试文件放入spec/requests文件夹的命令。然而,他编写的所有测试都与Controller

ruby-on-rails - rails : Methods shared by multiple controllers

我有两个Controller,即1)carts_controller2)订单ControllerclassCartsController注意:method3正在使用method1和method2。CartsController有showcart.html.erbView,它使用method3并且工作正常。现在在订单View中,我需要显示购物车(showcart.html.erb),但由于辅助程序method3是在carts_controller中定义的所以它无法访问它。如何解决? 最佳答案 由于您使用的是Rails4(这种方法应该也

ruby-on-rails - Controller : Circular dependency detected while autoloading constant 中的 Rails 4 运行时错误

如果我遗漏了什么,请告诉我。我不明白为什么无法访问我的views/references/文件夹。new.html.erb和index.html.erb都不可用。当我转到localhost:3000/references时,我的错误是:RuntimeErrorinReferencesController#indexCirculardependencydetectedwhileautoloadingconstantReferencesController我相信这是设置,它不应该是Rails问题,因为我的其他Controller工作正常。我的路线文件中有resources:reference

ruby-on-rails - rails 3 : Call functions inside controllers

如果我想在Controller内部调用函数,我应该把它们放在哪里? 最佳答案 如果您希望它在Controller本地,那么您需要做的就是将它添加到您希望使用的Controller。privatedefmyfunctionfunctioncode.....end对于所有Controller,您可以将它放在应用程序Controller中,因为所有Controller都是子类。应用程序Controllerprotecteddefmyfunctionfunctioncode.....end如果你想访问你的View,那么你可以创建一个助手应用

ruby-on-rails - ruby on rails 中的 Controller 和 Action 有什么区别?

谁能告诉我ruby​​onrails中Controller和Action之间的区别?我从官方Rails指南中获取了这个定义:Acontroller'spurposeistoreceivespecificrequestsfortheapplication.Routingdecideswhichcontrollerreceiveswhichrequests.Often,thereismorethanoneroutetoeachcontroller,anddifferentroutescanbeservedbydifferentactions.Eachaction'spurposeistoc

ruby - 破解 rails.vim 以与 Padrino 一起工作

我最近克隆了rails.vim(vim-rails),希望对其进行修改以用于Padrino项目。目前我正在尝试获取Rcontroller命令不仅可以查看app/controllers(非常适合rails),还可以查看项目中具有名为“controllers”的子文件夹的任何文件夹。因此,当我在命令模式下键入Rcontroller并点击Tab键时,我应该能够通过Tab键浏览admin/controllers/base.rb。,admin/controllers/accounts.rb,app/controllers/events.rb等。这将使插件的用户跳转到Padrino应用程序的“子应

javascript - 我应该如何延迟加载 Ext JS MVC Controller 、 View 、存储和模型?

我们使用ExtJSMVC作为插件/主机架构的前端技术,其中存在一个主机并且可以通过xcopy轻松安装许多插件。每个插件都有一个ExtJS应用程序,每个插件都会在页面加载时注册自己。整个应用程序是一个SinglePageApplication(SPA).我们现在遇到的主要问题是,我们安装了10多个插件,每个插件至少有10个Controller,以及50多个View、存储和模型。因此,当我们刷新页面(F5)时,我们应该等待将近30秒,以便大约200个HTTP请求到达服务器,并返回大约3MB的响应。虽然应用了缓存,但这根本不是我们想要的。甚至不是第一次。我想即使是外行也会接受这样的论点,即要

javascript - AngularJS:在多个模块之间共享工厂

假设我有一个名为App的模块,它注入(inject)了另外两个名为factories和controllers的模块:varapp=angular.module("app",["factories","controllers","directives"]).run(function($rootScope,userFactory){userFactory.property="someKickstartValue";});factories模块包含所有工厂:varfactories=angular.module("factories",[]),factory=factories.factor

javascript - AngularJS 应用程序 : Load data from JSON once and use it in several controllers

我正在开发一个使用AngularJS作为框架的移动应用程序,目前我的结构与此类似:app.config(['$routeProvider',function($routeProvider){$routeProvider.when('/',{templateUrl:'pages/home.html',controller:'homeCtrl'}).when('/one',{templateUrl:'pages/one.html',controller:'oneCtrl'}).when('/two',{templateUrl:'pages/two.html',controller:'two