草庐IT

index_name

全部标签

Ruby Rack - 安装一个默认读取 index.html 的简单 Web 服务器

我正在尝试从本教程中获取一些信息:http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder基本上我想要一个文件config.ru告诉rack读取当前目录,这样我就可以访问所有文件,就像一个简单的apache服务器一样,还可以读取带有索引的默认根目录.html文件...有什么办法吗?我当前的config.ru看起来像这样:runRack::Directory.new('')#thiswouldreadthedirectorybutitdoesn'tsettheroottoindex.htmlmap'/'dofile=File.re

ruby-on-rails - 带连接的 Rails named_scopes

我正在尝试创建一个使用连接的named_scope,但尽管生成的SQL看起来正确,但结果却是垃圾。例如:classClip"INNERJOINseriesONseries.id=clips.owner_idINNERJOINshowsonshows.id=series.show_id",:conditions=>"shows.visible=1ANDclips.owner_type='Series'"}(一个剪辑属于一个系列,一个系列属于一个节目,一个节目可以是可见的或不可见的)。Clip.all可以:SELECT*FROM`clips`Clip.visible.all可以:SELEC

ruby-on-rails - Rails belongs_to 关联(与 :class_name) returns nil

我是Rails开发的新手,遇到了一个小的关联问题。我想给一个关联起一个不同于它链接到的模型的名字。我有以下两个模型:classUser"User"#Sowecancallevent.admintoretrievetheUserwhoownsthisEventend我按如下方式构建用户:event=event.create!:title=>"NewEvent"user=User.create!:username=>"thinkswan"user.events当我进入控制台时,我收到以下信息:irb>user=User.find(1)irb>user.events=>[#]irb>even

ruby-on-rails - Elasticsearch 和轮胎 : Using Mapping and to_indexed_json

在阅读Tire时文档,我的印象是您应该使用mapping或to_indexed_json方法,因为(我的理解是..)使用了mapping提供to_indexed_json。问题是,我发现一些教程同时使用了这两种方法。为什么?基本上,我的应用程序现在可以使用to_indexed_json但我无法弄清楚如何设置某些属性的提升值(因此我开始查看映射的原因)并且我想知道同时使用两者是否会造成一些冲突。 最佳答案 虽然mapping和to_indexed_json方法是相关的,但实际上它们有两个不同的目的。mapping方法的目的是为索引中的

ruby-on-rails - Rails 4 迁移 : has_and_belongs_to_many table name

我目前正在尝试将Rails3.2应用程序切换到Rails4.0。但是我对has_and_belongs_many模型有一个问题。我创建了一个测试应用程序,但我遇到了同样的问题。这就是我所做的:创建了两个模型:foo_clip和foo_urlclassFooClip在此之后我更新了迁移文件:classCreateFooClips现在我已经为has_and_belongs_to_many表创建了迁移文件classCreateFooClipsFooUrls作为最后一步,我创建了一个用于测试的种子文件:foourl1=FooUrl.create!(:url=>'http://www.googl

ruby-on-rails - Rails 4 + Devise : Invalid route name, 已在使用中

我正在按照此操作方法在成功注册后修改确认页面。https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration)我按照它所说的做了所有事情,但我得到了这个错误:in`add_route':Invalidroutename,alreadyinuse:'new_user_session'(ArgumentError)Youmayhavedefinedtworouteswiththesamenameusingthe`:as`o

ruby - each_with_index_do 索引从 1 开始

我在Rails应用程序的View上使用ruby​​迭代器,如下所示:...我想加上1..而不仅仅是说:@document.data会得到让上面的索引从1开始的技巧。但是,遗憾的是,上面的代码索引仍然是0到data.length(实际上是-1)。那么我做错了什么,我需要索引等于1-data.length...不知道如何设置迭代器来执行此操作。 最佳答案 除非你使用像1.8这样的旧Ruby(我认为这是在1.9中添加的,但我不确定),你可以使用each.with_index(1)来获得1-基于枚举器:在你的情况下它会是这样的:...

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

ruby - 冒号(:) appears as forward slash (/) when creating file name

我正在使用日期和时间来标记我正在创建的新文件,但是当我查看该文件时,冒号是一个正斜杠。我正在使用10.7+在Mac上开发这是我使用的代码:File.open("#{time.hour}:00,#{time.month}-#{time.day}-#{time.year}","a")do|mFile|mFile.syswrite("#{pKey}-#{tKey}:\n")mFile.syswrite("Itemsclosed:#{itemsClosed}|Totalitems:#{totalItems}|Percentclosed:%#{pClosed}\n")mFile.syswrite

ruby-on-rails - rails : Testing named scopes with RSpec

我是测试Rails网络应用程序和RSpec的新手。我使用遗留代码并需要添加测试。那么使用RSpec测试查找器和命名范围的最佳方法是什么?我在Google中找到了一些方法,但它们并不理想。例如:http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-railsit"excludesusersthatarenotactive"do@user=Factory(:user,:active=>false)User.active.should_notinclude(@user)e