草庐IT

pages_queried

全部标签

ruby-on-rails - 在 Rails 3 中使用 current_page 时为 "No routes matches"

有没有人遇到过使用current_page时路由神秘地变得无法检测到?在Rails3中?即使使用包含路由、View和Controller的完全生成的脚手架,我也会收到“无路由匹配”错误。代码如下:ifcurrent_page?(:controller=>'users',:action=>"show")如果我向routes.rb添加一个“匹配”命令,它工作正常,但如果资源已经创建,为什么我需要这样做呢?我错过了什么? 最佳答案 如果你只是想测试当前的Controller,你可以这样做:ifparams[:controller]=='u

ruby-on-rails - save_and_open_page 和 spork,spork 正在丢失测试套件/输出

当我用spork运行我的rspec测试时,每次我使用capybara的save_and_open_page时,spork都会丢失测试套件......或者可能不再输出任何东西......查看日志#=>withoutsave_and_open_page09:04:24-INFO-SporkserverforRSpec,Test::Unitsuccessfullystarted09:04:24-INFO-Guard::RSpecisrunning09:04:24-INFO-RunningallspecsRunningtestswithargs["--drb","-f","progress",

ruby-on-rails - ruby rails : How would i stay on the same page if the post is not saved?

defcreate@addpost=Post.newparams[:data]if@addpost.saveflash[:notice]="Posthasbeensavedsuccessfully."redirect_toposts_pathelseflash[:notice]="Postcannotbesaved,pleaseenterinformation."endend如果帖子未保存,则会重定向到http://0.0.0.0:3000/posts,但我需要留在页面上,带有文本输入字段,以便用户可以输入数据。后模型classPosttruevalidates:content,:pr

ruby-on-rails - 传递给 Capybara::Queries::SelectorQuery 的未使用参数

我有这样的规范:it'containsDeletelink'doexpect(page).tohave_link('Delete',admin_disease_path(disease))end当我运行规范时,它会在控制台中返回警告:UnusedparameterspassedtoCapybara::Queries::SelectorQuery:["/admin/diseases/913"]我该如何解决这个问题? 最佳答案 expect(page).tohave_link('Delete',href:admin_disease_pa

ruby-on-rails - rails 4 : Flash message persists for the next page view

我在布局中使用以下代码来显示两种类型的即显消息:它们都工作正常,但无论何时触发一个,它仍会出现一次额外的页面View。我没有使用任何缓存gem。为什么会这样?我该如何解决? 最佳答案 使用flash.now而不是flash.flash变量旨在在redirect之前使用,并且它会在一个请求的结果页面上持续存在。这意味着如果我们不redirect,而不是简单的render一个页面,flash消息将持续存在两个请求:它出现在呈现的页面上但仍在等待重定向(即第二个请求),因此如果您单击链接,消息将再次出现。为了避免这种奇怪的行为,在渲染而不

ruby-on-rails - Kaminari & Rails 分页 - 未定义的方法 `current_page'

我搜索了又搜索,但没有解决我的问题。这是我的Controller:defshow@topic=Topic.find(params[:id])@topic.posts=@topic.posts.page(params[:page]).per(2)#2fordebuggingend这很好用,因为主题View被缩减为两个帖子。但是,当我将其添加到show.html.erb时:我收到这个错误:undefinedmethod`current_page'for# 最佳答案 尝试:defshow@topic=Topic.find(params[:

ruby - 页面对象模型 : why not include assertions in page methods?

第一张海报。我从事UI自动化工作多年,但直到最近才被介绍/受命使用页面对象模型。其中大部分是常识,包括我已经使用过的技术,但有一个特别好的地方我无法在自己的脑海中证明,尽管广泛搜索了合理的解释。我希望这里有人能启发我,因为这个问题在我尝试将POM与我自己的最佳实践集成时引起了一些惊愕。来自http://code.google.com/p/selenium/wiki/PageObjects:Thecodepresentedaboveshowsanimportantpoint:thetests,notthePageObjects,shouldberesponsibleformakingas

ruby-on-rails - rails : ActiveRecord query based on association value

我有2个模型。Report和Server有belongs_to和has_many关系。我使用delegate创建了一个访问器方法允许Report找到其关联的Server.company_id.现在,我想查询Report这让我可以找到所有Report与特定的Server相关联具有特定的company_id属性5.这是我的两个模型。是的,我知道自Report以来当前查询将无法正常工作。没有属性company_id.不,我不想存储company_idReport内部因为该信息不属于Report.举报classReport:serverclass服务器classServer

ruby-on-rails - rails 5 : ActiveRecord OR query

如何在Rails5ActiveRecord中执行或查询?此外,是否可以在ActiveRecord查询中将or与where链接起来? 最佳答案 在ActiveRecord查询中将or子句与where子句链接起来的能力将在Rails5。查看relateddiscussionandthepullrequest.因此,您将能够在Rails5中执行以下操作:获取id1或2的post:Post.where('id=1').or(Post.where('id=2'))其他一些例子:(A&&B)||C:Post.where(a).where(b).

ruby-on-rails - rails : How to change the title of a page?

在不使用插件的情况下,在Rails应用中为页面创建自定义标题的最佳方法是什么? 最佳答案 在你的View中做这样的事情:布局文件中的内容如下:也可以将content_for和yield(:title)语句封装在辅助方法中(正如其他人已经建议的那样)。但是,在这种简单的情况下,我喜欢将必要的代码直接放入特定的View中,而无需自定义助手。 关于ruby-on-rails-rails:Howtochangethetitleofapage?,我们在StackOverflow上找到一个类似的问题