草庐IT

do_something_after_f

全部标签

ruby-on-rails - ruby rails : How do you list the partial paths that are rendered for a page?

我希望列出为我的应用程序中的每个页面呈现的部分内容。例如,当显示app/tasks/index.html.erb页面时,我想向用户显示如下内容:Partialsrenderedforthispage:tasks/_list.html.erbtasks/_button.html.erbtasks/_navigation.html.erb在RubyonRails中有什么方法可以做到这一点吗? 最佳答案 是的,在Rails中完全可以做到这一点!正如bdares在他的评论中指出的那样,用于模板渲染的行出现在日志中。但他们最初是如何到达那里的

ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?

我正在尝试在prawn类中使用rails3.2助手,但rails抛出:undefinedmethod`number_with_precision'for#Prawn类classQuotePdfControllerdefshow@quote=current_user.company.quotes.where(:id=>params[:id]).firsthead:unauthorizedandreturnunless@quoterespond_with@quote,:layout=>!params[:_pjax]do|format|format.pdfdosend_dataQuotePd

ruby-on-rails - RubyOnRails : How do I use helper methods in Rails Console?

可能是我的设置有问题:irb(main):001:0>truncate("Onceuponatimeinaworldfarfaraway",:length=>17)NoMethodError:undefinedmethod`truncate'formain:Objectfrom(irb):1from/usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in`start'from/usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/ra

ruby-on-rails - rails : How do I autocomplete search for Name but save ID?

我用过这个视频http://railscasts.com/episodes/102-auto-complete-association-revised在我的应用程序的表单中设置自动完成搜索输入。(该视频可能仅供成员(member)使用,因此我也会发布我的代码。本质上,它会搜索数据库(名称)的一列,并在您键入时在下拉列表中自动完成。这一切都很好,但是,我想要什么表单要做的是提交与名称相关的ID,而不是名称本身。我假设没有简单的方法可以仅在View中执行此操作。任何帮助都会很棒。下面的代码,让我知道是否有任何其他代码有帮助。谢谢Controller:defgame_namegame.try

ruby-on-rails - ruby rails : why do i get message for javascript and css after rails s?

railss=>StartedGET"/assets/application.css?body=1"for127.0.0.1at2011-10-1103:37:03-0900Servedasset/application.css-304NotModified(0ms)StartedGET"/assets/home.css?body=1"for127.0.0.1at2011-10-1103:37:03-0900Servedasset/home.css-304NotModified(0ms)StartedGET"/assets/jquery_ujs.js?body=1"for127.0.0

ruby - 为什么 'undefined method ` assert_equal' ' is thrown even after requiring ' test/unit'

我打开irb并输入:require'test/unit'但是当我使用assert_equal方法时,出现以下错误:NoMethodError:undefinedmethod'assert_equal'formain:Object。为什么即使在需要“测试/单元”之后也会发生这种情况? 最佳答案 assert_equal是在Test::Unit::TestCase的子类上定义的,因此仅在该类中可用。您可能会成功地使用includeTest::Unit::TestCase将这些方法加载到当前范围。更有可能的是,您最好将测试写在一个短文件中

ruby - `var = something rescue nil` 行为

在Ruby中,您可以在赋值结束时编写rescue以捕获可能出现的任何错误。我有一个函数(如下:a_function_that_may_fail),如果不满足某些条件,让它抛出错误很方便。以下代码运行良好post={}#OtherHashstuffpost['Caption']=a_function_that_may_failrescuenil但是,如果函数失败,我什至不希望设置post['Caption']。我知道我能做到:beginpost['Caption']=a_function_that_may_failrescueend但这感觉有点过分-有更简单的解决方案吗?

ruby-on-rails - rails : Command not Found after successful install

所以我安装了ruby​​、gems和rails-但是每当我输入rails时,我都会收到rails:Commandnotfound.错误。我转储了我的本地gem,我将在下面包含***LOCALGEMS***actionmailer(3.2.7)actionpack(3.2.7)activemodel(3.2.7)activerecord(3.2.7)activeresource(3.2.7)activesupport(3.2.7)arel(3.0.2)bigdecimal(1.1.0)builder(3.0.0)bundler(1.1.5)daemon_controller(1.0.0)

ruby-on-rails - Ruby on Rails + Sidekiq : How do I change a scheduled job start time?

我最近开始使用Sidekiq并注意到它有一个我一直在寻找的很棒的功能:UserMailer.delay_until(5.days.from_now).find_more_friends_email基本上我可以在未来安排工作,所以我不需要我的应用程序持续轮询具有开始时间的新事件。现在这很有用,但我如何更改作业的开始时间?通常一些预定的事件会更改其开始时间。我如何在sidekiq中复制它?我知道我可以删除作业并创建一个新作业,但是否可以只修改开始时间?编辑:我建立在OtoBrglez的想法之上,这里是记录的代码:moduleTaskStuffclassTaskSetterincludeSi

ruby - 何时以及为何在 Ruby 中使用 Loop Do Construct

我最近遇到了一个使用LoopDo的问题/解决方案。到目前为止,我在学习Ruby编程时很少看到这一点(我是没有CS经验的初学者)。#Writeafunction,`nearest_larger(arr,i)`whichtakesanarrayandan#index.Thefunctionshouldreturnanotherindex,`j`:thisshould#satisfy:##(a)`arr[i]1distancetotheleft"donearest_larger([8,2,4,3],2).should==0endit"handlesacasewithananswer>1dis