草庐IT

ACTION-VIEW

全部标签

ruby-on-rails - 我可以在 render.js 上执行的 View 中使用 CoffeeScript 吗?

我需要做什么才能在RailsJSView中使用CoffeeScript?例如:defindexformat.js{render:layout=>false}end我需要做什么才能让Rails使用index.js.coffee? 最佳答案 Johnny的回答是正确的。如果您查看pullrequest链接到CoffeeBeans页面,你有dhh说Oncewehaveafast,cleanimplementation,it'swelcomeincore.3.2isamorelikelytarget,though.我在Railsconf上与

ruby-on-rails - Controller 所有 Action 的相同实例变量

我有一个RailsController,其中定义了两个操作:index和show。我在index操作中定义了一个实例变量。代码如下:defindex@some_instance_variable=fooenddefshow#somecodeend如何访问show.html.erb模板中的@some_instance_variable? 最佳答案 您可以使用前置过滤器为多个操作定义实例变量,例如:classFooController[:index,:show]defcommon_content@some_instance_variab

ruby-on-rails - 在 Ruby on Rails 中查找未使用的 View /部分

我目前正在从事一个大型的RubyonRails项目。它已经足够老,也足够大,以至于不清楚是否所有View都在实际使用中。有没有可以生成未使用View文件列表的脚本/插件? 最佳答案 我写了一个脚本来查找未使用的部分/View。不过,我假设“未使用”意味着存在一个View文件,但没有为其定义Controller方法(不再)。该脚本不检查View是否被调用,因为没有从默认路由到它的链接。这会复杂得多。将以下脚本放在应用程序的脚本文件夹中:#!/usr/bin/envrubyrequire'config/environment'(Dir[

ruby - Selenium 滚动元素进入(中心) View

当一个元素在selenium的View之外并且试图与之交互时,selenium通常会首先隐式地将元素滚动到View中。这很棒,只是烦人的是它通常将元素放入View中。我的意思是,如果元素位于窗口下方,它会向下滚动足够多直到元素刚好与窗口边缘接壤。通常这很好,但是当在周围有边框的网站上工作时,这将导致许多此类错误Selenium::WebDriver::Error::UnknownError:unknownerror:Elementisnotclickableatpoint(438,747).Otherelementwouldreceivetheclick:...因为通常网页的边框都在它

ruby-on-rails - 保留 ActiveAdmin 布局的 ActiveAdmin 自定义 View

我有一个带有ActiveAdmingem的Rails3应用程序。我的目标是在自定义View中呈现自定义Controller以保持其布局。我成功地使用以下代码在自定义View中制作自定义Controller渲染:页面.rb:ActiveAdmin.register_page'Pages'docontentonly::indexdorender'index'endcontentonly::editdorenderpartial:'edit'endcontrollerdodefindex@search=Page.includes(:translations).where("page_tran

ruby-on-rails - 匿名 Controller 的 Rspec stubing View

我正在尝试在应用程序Controller上测试一种方法,该方法将用作前置过滤器。为此,我在测试中设置了一个匿名Controller,并应用了before过滤器以确保其正常运行。目前的测试是这样的:describeApplicationControllerdocontrollerdobefore_filter:authenticateddefindexendenddescribe"userauthenticated"dolet(:session_id){"session_id"}let(:user){OpenStruct.new(:email=>"pythonandchips@gmail

ruby-on-rails - 为什么仍然可以在 View 中访问私有(private)辅助方法?

只是另一个“为什么会这样”的问题:我注意到私有(private)辅助方法仍然可以在View中访问。为什么?有没有办法防止这种情况(例如,当有只能从另一个助手内部调用的助手方法时)? 最佳答案 助手是modulesthatgetmixedin意见。这意味着帮助程序中的公共(public)、protected和私有(private)方法成为View上的公共(public)、protected和私有(private)方法。我认为您实际上无法从View中隐藏辅助方法。你需要做一些事情,比如有一个你在帮助器中实例化的帮助器类,然后委托(del

ruby-on-rails - 为什么使用 before_action 没有双重渲染?

我想知道为什么在before_action中有redirect_to或render时没有双重渲染。考虑这个例子:classSomeController我看到before_action如果不能重定向就没用了,但它是如何制作的?如果我评论before_action它会抛出异常。before_action是如何实现的而不导致双重渲染? 最佳答案 参见RailsGuideoncontrollers:Ifa"before"filterrendersorredirects,theactionwillnotrun.Ifthereareadditi

ruby-on-rails - 没有路由匹配 { :controller= >"stocks", :action= >"create"} RSpec Rails 3

我不明白为什么我在运行RSpec时收到此错误消息:Failure/Error:post:createActionController::RoutingError:Noroutematches{:controller=>"stocks",:action=>"create"}controllerstocks存在,actioncreate存在,它应该使用的路由是这样的:match'stocks/:user_id'=>'stocks#create',:via=>:post,:as=>:query路由文件:FruthScreener::Application.routes.drawdoroot:

ruby-on-rails - rails : Add Custom action to resource

我有一个故事Controller,我已将其映射为资源。我向stories_controller添加了2个新方法,'top'和'latest'。但是当我尝试访问example.com/stories/top时,出现“没有ID=top的故事”错误。如何更改路由以识别这些URL? 最佳答案 在Rails2.x中尝试:map.resources:stories,:collection=>{:top=>:get,:latest=>:get}在Rails3.x中:resources:storiesdocollectiondoget'top'ge