草庐IT

URL 重写不起作用,Google 认为我有来 self 的无 www 域的反向链接

全部标签

ruby-on-rails - 如何从字符串中提取包含非英文字符的 URL?

这是一个简单的脚本,它采用其中包含德语URL的anchor标记,并提取URL:#encoding:utf-8require'uri'url=URI.extract('München')putsurlhttp://www.example.com/wp-content/uploads/2012/01/Mextract方法在ü处停止。我怎样才能让它与非英文字母一起使用?我正在使用ruby​​-1.9.3-p0。 最佳答案 Ruby的内置URI在某些方面很有用,但在处理国际字符或IDNA地址时,它并不是最佳选择。为此,我建议使用Addres

ruby-on-rails - Hartl 教程中的 bundle exec rspec spec/requests/static_pages_spec.rb 不起作用

我正在按照MichaelHartl的ruby​​onrails教程测试示例应用程序(3.2.1测试驱动开发),但在键入bundleexecrspecspec/requests/static_pages_spec.rb后出现以下错误/home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in`require':cannotloadsuchfile--zip/zip(LoadErr

ruby - 何时在模块的方法中使用 self

我的模块定义如下:moduleRG::Statsdefself.sum(a,args={})a.inject(0){|accum,i|accum+i}endend要使用这个方法,我只需要包含这个定义的文件,这样我就可以:RG::Stats.sum(array)还有RG::Stats.method(:sum)但是,如果我需要使用RG::Stats.instance_methods了解方法列表,我会得到一个空数组。这是因为我使用了self。如果我省略self,则RG::Stats.instance_methods会给出方法列表,但我无法再访问它们。问题是:如何在模块的方法定义中使用self

ruby-on-rails - Ruby/Rails - 在新窗口中从 Controller 打开 URL

我在我的应用程序Controller中并且有一个url字符串。我如何告诉应用程序在新窗口中打开浏览器中的url。有没有办法将目标设置为空白?例如deflink@url='www.google.com'****???Open@url??***withtargetblank?end 最佳答案 这不可能直接从Controller执行。使用redirect_to@url具有在同一“窗口”中打开URL的效果,因为它只是将HTTP重定向指令发送回浏览器。redirect_to无法打开新窗口。Controller驻留在服务器端,打开一个新窗口属于

ruby -::MyClass Ruby 作用域运算符是做什么的?

::MyClass/MyModule作用域运算符在Ruby中的作用是什么,它的目的是什么? 最佳答案 这在全局范围内明确引用了MyClass。如果在全局范围内有一个MyClass,但在SomeModule内部也有一个MyClass,那么从SomeModule内部引用MyClass将引用模块内部的MyClass,而不是全局MyClass。说::MyClass明确引用全局范围内的MyClass。classMyClassdefself.somethingputs"GlobalMyClass"endendmoduleSomeModulecl

ruby-on-rails - 获取 URL 字符串参数?

我的数据库中有这个URL,在“位置”字段中:http://www.youtube.com/watch?v=xxxxxxxxxxxxxxxxxxx我可以通过@object.location获取,但是如何获取v的值呢?我的意思是,从URL字符串中获取"xxxxxxxxxxxx"? 最佳答案 require'uri'require'cgi'#useURI.parsetoparsetheURLintoitsconstituentparts-host,port,querystring..uri=URI.parse(@object.locati

ruby-on-rails - Rails - 如何 'merge' 或将值附加到 URL 中的数组?

我试图在URL中传递一个数组,它工作正常,但我想知道我如何才能插入或删除某些值?例如,我有一个看起来像这样的链接:http://localhost:3000/pins?genre_ids[]=1,2,3我想构建一组链接,可以从这个URL数组中插入或删除数字。目前,我拥有的每个链接都只是完全更改了genre_ids[]值,我想在其中添加或根据需要删除。这是我建立链接的代码...[genre[0].id]}))%>我认为我所追求的是params.merge()但对于params[:genre_ids]的值希望你能明白我的意思?如果当前URL读取/pins?genre_ids[]=1,2,3

ruby - 如何在处理任何数据之前测试 open-uri url 是否存在

我正在尝试使用ruby​​(1.8.6)中的“open-uri”处理链接列表中的内容,但是当一个链接断开或需要身份验证时出现错误时,就会发生错误:open-uri.rb:277:in`open_http':404NotFound(OpenURI::HTTPError)fromC:/tools/Ruby/lib/ruby/1.8/open-uri.rb:616:in`buffer_open'fromC:/tools/Ruby/lib/ruby/1.8/open-uri.rb:164:in`open_loop'fromC:/tools/Ruby/lib/ruby/1.8/open-uri.

ruby - Sinatra 变量作用域

采用以下代码:###Dependenciesrequire'rubygems'require'sinatra'require'datamapper'###Configurationconfig=YAML::load(File.read('config.yml'))name=config['config']['name']description=config['config']['description']username=config['config']['username']password=config['config']['password']theme=config['conf

ruby - 何时在 Ruby 中使用 'self'

这个方法:defformat_stations_and_datefrom_station.titelize!iffrom_station.respond_to?(:titleize!)to_station.titleize!ifto_station.respond_to?(:titleize!)ifdate.respond_to?(:to_date)date=date.to_dateendend当date为nil时出现此错误:NoMethodError(Youhaveanilobjectwhenyoudidn'texpectit!Theerroroccurredwhileevaluat