草庐IT

for语句

全部标签

ruby-on-rails - Faraday::ConnectionFailed,Connection refused - connect(2) for “localhost” port 9200 Error Ruby on Rails

我正在尝试使用RubyonRails在我的应用程序中添加Searchkickgem,但是当我在搜索框中键入一个词时,我的应用程序中出现此错误。我已经根据需要安装了elasticsearch和最新版本的java,但错误仍然是一样的。这是我得到的错误:Faraday::ConnectionFailedinPostsController#searchConnectionrefused-connect(2)for"localhost"port9200这是我的代码:终端显示已安装Elasticsearch:终端Warning:elasticsearch-1.7.3alreadyinstalled

ruby - 使用 YARD for Ruby 文档的内部评论?

我正在将我维护的ruby​​gem从RDoc切换到YARD文档。但是,代码中有一些关键注释只需要保留在代码中,不应出现在文档中。例如:###SomeClassdocumentationhere.#--#CRITICALcommentthatshouldbeinthecodebutnotinthedocumentation,#andmustbeatthisparticularspotinthecode.#++#moredocumentationthatfollowsthecriticalcommentblock,butthispart#shouldbeinthegenerateddocu

ruby - Ruby 中的语句和表达式有什么区别?

我知道在Ruby中,几乎所有东西都是表达式。即使是其他语言中的if-else语句、case语句、赋值语句、loop语句在Ruby中也是表达式。所以我想从Ruby的角度了解,statement和expression有什么区别? 最佳答案 Ruby中表达式和语句没有区别。一切都计算为一个值,所以一切都是表达式。 关于ruby-Ruby中的语句和表达式有什么区别?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c

ruby - 'case' 语句如何使用常量?

我正在使用Ruby1.9.2和RubyonRails3.2.2。我有以下方法:#Note:The'class_name'parameterisaconstant;thatis,itisamodelclassname.defmy_method(class_name)caseclass_namewhenArticlethenmake_a_thingwhenCommentthenmake_another_thingwhen...then...elseraise("Wrong#{class_name}!")endend我想明白为什么在上面的case语句中,当我执行方法调用时它总是运行else“

ruby-on-rails - rails : Do I need a controller for each model?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭9年前。Improvethisquestion我有一个包含4个模型的Rails应用程序。我只在一个Controller操作中访问这4个模型。我目前有4个不同的Controller来处理这些模型。我想知道将这4个Action塞入一个Controller是否是一种不好的做法。当前设置:classGmDataController建议的设置:classDashboardController

ruby-on-rails - 无法安装 gems,因为 "undefined method ` invoke_with_build_args' for nil :NilClass"

我在Rubyrails上,我正在安装RubyonRails。我正在尝试安装gems,但它没有发生,我不确定为什么以及如何修复它。$geminstallbundlerERROR:Loadingcommand:install(LoadError)dlopen(/Users/nthulanemakgato/.rbenv/versions/2.1.1/lib/ruby/2.1.0/x86_64-darwin13.0/openssl.bundle,9):Librarynotloaded:/usr/local/opt/openssl/lib/libssl.1.0.0.dylibReferenced

ruby-on-rails - Aws::S3::Presigner undefined method credentials for nil:NilClass in Ruby

我使用了aws-sdk-coregem我在从aws获取url时遇到错误以下是我的代码definitialize(bucket:,region:)@bucket=bucketclient=Aws::S3::Client.new(region:region)@signer=Aws::S3::Presigner.new(client:client)enddefsign(key,expires_in:3600)@signer.presigned_url(:get_object,bucket:@bucket,key:key,expires_in:expires_in)end我遇到了错误NoMet

ruby-on-rails - 了解 `include` mixin 模块的 "subsequent"语句行为

我试图理解include语句在多个Mixin中使用时的行为。也就是说,我有这些声明:classArticleDoubleIncludedModule将被包含在Article类中多少次?也就是说,由于DoubleIncludedModule的“后续”包含(首先在Article类中,然后在Article包含的AModule中类本身),将是Ruby自动处理的“双重包含”问题,还是DoubleIncludedModule(错误地)包含两次?当然,我想包含DoubleIncludedModule模块仅一次。我怎样才能以正确的方式做到这一点(也许通过使用一些RubyonRails方法)?

ruby-on-rails - If 语句中额外的 Ruby 行会导致 Haml 出现问题吗?

我试图在我的一个HamlView中的If/Else语句中放置一些(未呈现的)注释,但它似乎会导致问题。我想要以下代码:-#Stufflike______activatestheifstatement-if@condition(Somecode)-#Stufflike_____activatestheelsestatement-else(Someothercode)不幸的是,Rails向我抛出这个错误:Got"else"withnopreceding"if"如果我删除“其他”注释,即-#Stufflike______activatestheifstatement-if@condition

ruby-on-rails - link_to 与 url_for 与 Rails 中的路径

我开始学习RubyonRails,我有一些疑问。我已经看到Railsdocumentation但我完全不明白它们之间的区别:url_forlink_to路径我如何使用/发现我的应用程序的路径?此外,我可以在路径中发送一个参数,例如:有这样的东西吗? 最佳答案 url_for为您提供网站的完整url,例如:www.example.com/my/path将来自url_formy_path_url.link_to为您提供指向特定路径的链接,例如:link_toexample_path,"clickme"会导致clickme您也可以像这样将