草庐IT

How-does-Quora-rewrite-their-urls

全部标签

ruby-on-rails - 在 Rails 中使用主机和多个路径字符串创建 URL

我想使用端点和路径或主机和路径创建URL。不幸的是URI.join不允许这样做:pry(main)>URI.join"https://service.com","endpoint","/path"=>#pry(main)>URI.join"https://service.com/endpoint","/path"=>#我想要的是:"https://service.com/endpoint/path"。我怎样才能在Ruby/Rails中做到这一点?编辑:由于URI.join有一些缺点,我很想使用File.join:URI.join("https://service.com",File.j

ruby-on-rails - rails 4 : how to use OR between conditions on find methods

我的问题类似于thisone,但那里的答案都没有解决我的具体问题。我想找到类似这样的对象:conditions={first_name:@searchORlast_name:@search}Stuff.where(conditions)显然,这种语法是无效的,但这是我能想到的展示我想做的事情的最简单的方法。我想在复杂/复合条件下使用更简洁的哈希语法。我知道你可以用像这样的“纯字符串条件”手写出来Stuff.where("first_name=#{@search}ORlast_name=#{@search}")...但这不是我想知道的。更新看起来您可以对这样的数组执行OR:Stuff.w

ruby-on-rails - ruby + Mongoid : how to make a required field?

我使用Mongoid的githead版本(因为Rails4),我想制作一个字段必填文档:classMyClassincludeMongoid::Documentfield:name,type:String,required:true我有这个错误:Problem:Invalidoption:requiredprovidedforfield:name.Summary:Mongoidrequiresthatyouonlyprovidevalidoptionsoneachfielddefinitioninordertopreventun...我做错了什么? 最佳答案

jquery - 你能通过 url 发送 JSON 吗?

我有一个ruby​​散列,其中键是url,值是整数。我将散列转换为JSON,我想知道我是否能够通过AJAX请求在url中发送JSON,然后从参数散列中提取该JSON。另外,我将向客户端发送一个JSON化的ruby​​散列。如果我在我的AJAX函数中有一个成功的回调,我在其中接收到data变量中的数据,我该如何使用JQuery解析该JSON?如果我需要更具体一点,请告诉我。 最佳答案 是的,你可以毫无问题。无需手动编码/解码!你的代码应该是这样的:varjsonParam='{"name":"Edgar"}';//Samplejson

ruby - 在 Ruby 中解析 URL 以获得没有 "www"的子域或主域?

如果我有一个URL:http://www.example.com/page我想将其解释为:example.com但是,如果我有:http://blog.example.com/page我想回去:blog.example.com这很难吗? 最佳答案 使用Ruby的URI模块:require'uri'URI.parse('http://www.example.com/page').host=>"www.example.com"URI.parse('http://blog.example.com/page').host=>"blog.ex

Ruby linkify 用于字符串中的 url

有一些关于使用正则表达式链接文本的帖子。最受欢迎isthispost.但是我的规范有点棘手:describeTextFormatterdodefl(input)TextFormatter.gsub_links!(input){|link|"!!#{link}!!"}endit"shoulddetectsimplelinks"dol("http://www.cnn.com").should=="!!http://www.cnn.com!!"endit"shoulddetectmultilinks"dol("http://www.cnn.comhttp://boats.com?help.a

ruby - Delayed_job : how to use handle_asynchronously to work with a function?

函数是:defcreateuser(name,pass,time)putsname,pass,timeend我试试:handle_asynchronously:createuser("a","b","c")得到一个错误:语法错误,意外'(',期待keyword_end谢谢。===编辑===日本的用户数据库和北京的网络服务器。所以我用这种方式来创建用户。defcreateuser(name,pass,time)Net::HTTP.get(URI.parse("http://www.example.net/builduser.php?hao=#{name}&mi=#{pass}&da=#{

ruby - 使用正则表达式获取 URL 的域

我正在尝试获取给定URL的域。例如http://www.facebook.com/someuser/将返回facebook.com。给定的URL可以是以下格式:https://www.facebook.com/someuser(www.是可选的,但应忽略)www.facebook.com/someuser(http://不是必需的)facebook.com/someuserhttp://someuser.tumblr.com->这只能返回tumblr.com我写了这个正则表达式:/(?:\.|\/{2})(?:www\.)?([^\/]*)/i但它并没有像我预期的那样工作。我可以分部分

ruby - 使用 Fog 和 Ruby 生成预签名 URL 以将文件放入 Amazon S3

我正在使用Foggem生成预签名url。我可以成功执行此操作以获得对该文件的读取权限。这是我的做法:fog_s3=Fog::Storage.new({:provider=>'AWS',:aws_access_key_id=>key,:aws_secret_access_key=>secret})object_path='foo.wav'expiry=Date.new(2014,2,1).to_time.to_iurl=fog_s3.directories.new(:key=>bucket).files.new(:key=>object_path).url(expiry,path_sty

Ruby URI - 如何在 URL 之后获取完整路径

给定以下内容,如何获取URL的完整路径uri=URI("http://foo.com/posts?id=30&limit=5#time=1305298413")我只想要posts?id=30&limit=5#time=1305298413我试过uri.path并返回/posts和ui.query返回'id=30&limit=5' 最佳答案 您要找的方法是request_uriuri.request_uri=>"/posts?id=30&limit=5"如果需要,您可以使用任何您想要删除前导/的方法。编辑:要获取#符号后的部分,请使用