草庐IT

path-parameter

全部标签

Ruby - 将目录添加到 $LOAD_PATH - 它有什么作用?

这其实是关于这个问题的问题:Addingadirectoryto$LOAD_PATH(Ruby)将目录添加到$LOAD_PATH时会发生什么?是不是像JavaScript一样在执行上下文中添加一个脚本文件?(可以访问其他文件中的全局方法/对象)如果没有,如何调用当前目录下其他ruby文件的方法? 最佳答案 将/Users/you/scripts/ruby目录添加到加载路径时,可以使用:require'example'代替:require'/Users/you/scripts/ruby/example.rb'

ruby 正则表达式 : capture the path of url

我想从任何URL中提取其路径。例如:网址:https://stackoverflow.com/questions/ask路径:questions/ask应该不难:url[/(?:\w{2,}\/).+/]但我认为我使用了错误的模式来“忽略这个”('?:'-不起作用)。什么是正确的方法? 最佳答案 我建议您不要使用正则表达式来执行此操作,而是使用内置的URI库:require'uri'uri=URI::parse('http://stackoverflow.com/questions/ask')putsuri.path#results

ruby-on-rails - ruby on rails 中的 "_path"方法是什么?

我正在学习RoR,我对Controller和路由中使用的“_path”方法感到非常困惑。更具体地说,我指的是采用语法“(something)_path”的许多不同调用。据我所知,它们似乎都对URL或链接进行编码或操作。我很难掌握这种方法的使用,因为我无法弄清楚它的核心功能应该是什么。例如,我可以使用以下代码将旧的URL结构重定向到我的config/routes.rb文件中列出的Tweet实例的页面:get'/all'=>'tweets#index',as:'all_tweets'只有现在我才能在.erb文件中使用以下内容。请注意行尾的“_path”代码。我还可以使用以下代码在不同的.e

RubyGems + Cygwin : POSIX path not found by ruby. exe

我是Windows上的Ruby程序员,试图从Wincmd切换到Cygwin,但无法执行Rubygems的批处理文件。我已经将任何bin目录填充到WindowsPATH环境中。变量,包括存储可执行文件的Rubybin。然而,gems是由ruby​​.exe本身调用的,这会导致以下POSIX路径问题:duddle@duddledan/cygdrive/c/Ruby/ruby-186-398/bin$gem-vC:\Ruby\ruby-186-398\bin\ruby.exe:Nosuchfileordirectory--/cygdrive/c/Ruby/ruby-186-398/bin/g

ruby-on-rails - 摩卡 : How to add expectation of a method when there are multiple invocations with different parameters

我有一个RailsControllerAction要测试。在那个Action中,一个方法User.can?使用不同的参数多次调用。在其中一个测试用例中,我想确保User.can?('withdraw')被调用。但我不关心User.can的调用?与其他参数。defaction_to_be_tested...@user.can?('withdraw')...@user.can?('deposit')...end我在测试中尝试了以下:User.any_instance.expects(:can?).with('withdraw').at_least_once.returns(true)但是测

ruby-on-rails - rails : Unpermitted parameter in Rails 5

首先,我只想在发送到我的后端的当前对象中获取一个对象。我有这个简单的JSON(从表单生成):{"name":"Project1","project_criteria":[{"name":"Criterium1","type":"Type1","benefit":"1"},{"name":"Criterium2","type":"Type2","benefit":"3"}]}我的类(class):classProject项目Controller:defproject_paramsparams.require(:project).permit(:name,project_criteria:

ruby - Rails current_path helper ?

我正在开发具有以下路由条件的Rails3.2应用程序:scope"(:locale)",locale:/de|en/doresources:categories,only:[:index,:show]get"newest/index",as::newestend我有一个包含以下内容的Controller:classLocaleController我在模板中将它与类似的东西一起使用:=link_toset_locale_path(locale::de,return_to:current_path(locale::de))do=image_tag'de.png',style:'vertic

ruby - OS X 10.5 下 Ruby 的常规 GEM PATHS 是什么?

我的ruby​​在我的机器上有一个性能问题,我认为我已经隔离到加载库(当调用#require时),所以我试图弄清楚ruby​​是否正在为库搜索太多文件夹。当我运行时$gemenvironmentRubyGemsEnvironment:-RUBYGEMSVERSION:1.3.0-RUBYVERSION:1.8.6(2008-03-03patchlevel114)[universal-darwin9.0]-INSTALLATIONDIRECTORY:/Library/Ruby/Gems/1.8-RUBYEXECUTABLE:/System/Library/Frameworks/Ruby.

ruby - 全新安装 OSX 10.9.1 在尝试安装 gems 时返回 "undefined method ` path2class'"

我刚刚使用Homebrew和RVM安装了一个干净的Mavericks安装。brewdoctor和rvmrequirements都返回“allgood”,但是,当我在我的项目目录中运行bundleinstall时,我的大多数gem安装都很好,但少数安装失败并出现相同的以下错误:Bundler::GemspecError:Couldnotreadgemat/Users/NK/.rvm/gems/ruby-2.0.0-p353/cache/eventmachine-1.0.3.gem.Itmaybecorrupted.Anerroroccurredwhileinstallingeventma

ruby-on-rails - 我如何解决 "Missing host to link to! Please provide the :host parameter"? (返回率)

我正在关注RoRTutorial我被困在Listing9.15运行'bundleexecrspecspec/'后出现以下错误:1)AuthenticationauthorizationaswrongusersubmittingaPATCHrequesttotheUsers#updateactionFailure/Error:specify{expect(response).toredirect_to(root_url)}ArgumentError:Missinghosttolinkto!Pleaseprovidethe:hostparameter,setdefault_url_opti