草庐IT

iOS 7+ 关闭模态视图 Controller 并强制纵向

全部标签

ruby-on-rails - Ruby On Rails 自定义路由总是重定向到 Controller 的显示操作

我正在尝试创建一条新路线,以便我可以利用RoR的路径变量功能,即new_game_path。就我而言,我想使用load_game_path我已经为适当的Controller创建了一个Action,目前路由如下:resources:gamesdoget'load',on::collectionend每次我使用load_games_path它都使用正确的URI,但似乎重定向到GamesController的显示操作并显示游戏的继承显示View。我检查了rakeroutes,我看到我新创建的路线似乎是所需的路径/games/load(文件路径:/views/games/load.html.e

ruby - 如何使用 RuboCop 强制使用三元括号?

我有一个编码标准,建议无论表达式如何,三元组的初始参数都应始终在括号内。例如foo=(thing.baz?)?[]:东西.bar以下行为应视为违规:例如foo=thing.baz??[]:东西.bar是否可以使用Rubocop的内置Cops来实现这一点,或者这是否需要自定义Cop。如果可以,我将如何实现? 最佳答案 我看到了你的问题,所以我继续为你实现警察。名称是Style/TernaryParentheses,您想要的EnforcedStyle选项是require_parentheses(不是默认值。)#.rubocop.ymlS

ruby-on-rails - Capybara + RSpec 只能在 Controller 规范中看到空白页。为什么?

我正在尝试为一个简单的Controller编写Controller规范。但是,Capybara没有看到任何页面内容。但是,在我的浏览器中查看该网站的页面效果很好。我做错了什么?T。汉克斯!MycontrollerspecMyspec_helper.rbMyGemfile 最佳答案 您需要明确地告诉您的Controller规范您希望它渲染View才能使其正常工作。将您的规范更新为如下所示:require'spec_helper'describePostsControllerdorender_views#Renderthiscontro

ruby-on-rails - Rails 中带后备功能的动态命名空间 Controller

我对新的Rails应用程序有一个有点奇怪的要求。我需要构建一个应用程序,其中所有路由都在多个命名空间中定义(让我解释一下)。我想要一个应用程序,其中学校科目(数学、英语等)是namespace:%w[mathenglish].eachdo|subject|namespacesubject.to_symdoresources:studentsendend这很棒而且有效,但它需要我为每个主题创建一个命名空间StudentsController,这意味着如果我添加一个新主题,那么我需要创建一个新Controller。我想创建一个Base::StudentsController,如果Math:

ruby-on-rails - 为 ActiveAdmin Controller 设置过滤器 before_action

我想向ActiveAdminController添加before_action过滤器。我可以这样做吗:before_action:set_product,only:[:show,:edit,:update,:destroy]privatedefset_product@product=Product.find_by_name(params[:name])end 最佳答案 您可以从controllerdo...endDSL中访问Controller:ActiveAdmin.registerUserdobefore_action:set_

ruby-on-rails - 从 rake 任务调用 Controller

我想从rake任务中调用Controller操作。我的问题是准备http请求的最佳方法是什么?感谢所有提示。编辑:有人有其他提示吗?我试过这个但没有用:controller_obj=Controller.newcontroller.your_method我遇到了这个异常:rakeaborted!uninitializedconstantController编辑2:我试过:sess=ActionController::Integration::Session.newsess.post('/route','codes=3')但是我得到了(我在rake文件中需要'action_control

ruby-on-rails - 如何在 Rails Controller 操作的 RSpec 测试中指定查询字符串?

我有一个名为yearly_csv的操作。在此操作中,我执行两个操作,如需求和供应。defyearly_csvifdemand=='true'demand_csvelsesupply_csvendend我的View中有两个单选按钮来选择其中一个操作。现在我想在RSpec中单独测试每个操作。例如,一个供应规范和另一个需求规范。我的问题是如何将单选按钮值传递给yearly_csv操作(get)? 最佳答案 在RSpec的较新版本中,您必须使用params键声明查询字符串参数:get:yearly_csv,params:{demand:'t

ruby-on-rails - RSpec Controller 测试 : missing template on create

我有一个有趣的情况。我正在测试以下简单的创建操作:#willonlybeaccessedviaAjaxdefcreateclick=Click.new(params[:click])click.save#don'treallycarewhetheritssuccessorfailureend然后我有以下非常简单的Controller规范:require'spec_helper'describeClicksController,"creatingaclick"doit"shouldcreateaclickforevent"doxhr:post,:create,:click=>{:even

ruby - 如何使用 Whenever gem 强制 rake 任务在开发环境下运行

我正在使用Whenevergem运行rake任务。当我运行rake任务时,它在开发环境下运行,但当它在预定时间运行时,它指的是生产环境。如何强制在开发环境下运行预定的rake任务。据我所知,我将不得不使用RAILS_ENV变量,但无法弄清楚将它放在哪里。我认为,这与此处的Whenevergem无关。 最佳答案 在任何bash类型的shell中,您通常可以在运行时覆盖环境:RAILS_ENV=developmentraketask:name...您也可以编写一个小脚本来为您执行此操作:#!/bin/shexportRAILS_ENV=

ruby-on-rails - rails : Loading custom class from lib folder in controller

我创建了一个名为lib/services/my_service.rb的文件。#/lib/services/my_service.rbclassMyService...end我想在app/controllers/my_controller中使用它classMyController我收到一个错误消息,指出MyService是一个未初始化的常量。我尝试用导入它require'/lib/services/my_service.rb'但是我得到了cannotloadsuchfile--/lib/services/my_service.rb编辑:我尝试使用application.rb自动加载con