草庐IT

improved_regex_for_matching_urls

全部标签

ruby-on-rails - ruby rails : pluralize for other languages

我正在为非英语用户构建应用程序。现在,我使用英语名词来命名我的模型,但我更喜欢使用荷兰本土名词。由于约定使用表类名称的复数形式,我假设它是Rails中的复数方法(我不知道它位于何处)。如何更改pluralize方法及其位置?这会破坏Rails吗?我正在使用Rails2.3.5和Ruby1.8.7例子:Book类现在变成了书籍。我的Boek类变成了boeks,但是使用boeken在语法上是正确的 最佳答案 将您的规则添加到config/initializers中的inflections.rb文件。查看APIdocumentation:

ruby - 安装 RDoc 文档时出错 : incompatible encoding regexp match

上周,在一些gem安装或gem更新操作中,我收到了与这些类似的错误:ERROR:Whilegeneratingdocumentationforsinatra-1.3.1...MESSAGE:errorgeneratingC:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/doc/sinatra-1.3.1/rdoc/README_de_rdoc.html:incompatibleencodingregexpmatch(UTF-8regexpwithIBM437string)(Encoding::CompatibilityError)类似的:E

ruby-on-rails - Form_for "First argument in form cannot contain nil or be empty"错误

我不明白为什么会收到此错误,也不知道它的确切含义。Firstargumentinformcannotcontainnilorbeempty(Line3)添加新帖子//ErrorhereController:classPostsController"Yourpostwassaved"elserender"new"endenddefeditenddefupdateenddefdestroyendend 最佳答案 假设您从PostsController渲染它并使用传统的View名称,您的new方法应该创建一个新的Post并分配给它:def

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-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 : How to create table for a new model

我用railsgeneratemodelmynewmodelstring:namestring:description生成一个新模型。如何将这个新模型部署到我的开发数据库中?我的sqlite数据库中已经有一堆数据库。我试过了rakedb:migrate在db中生成这个新表似乎有问题。更新:添加了错误信息==CreateMynewmodels:migrating===============================================--create_table(:mynewmodels)rakeaborted!Anerrorhasoccurred,thisandal

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-on-rails - rails : how to set json format for redirect_to

我如何才能不重定向到html格式而是重定向到json?我想要这样的东西:redirect_touser_path(@user),format::json但这不起作用,我仍然重定向到html路径。 最佳答案 我又读了一些apidock...这很简单。我应该像这样在路径助手中指定格式:redirect_touser_path(@user,format::json) 关于ruby-on-rails-rails:howtosetjsonformatforredirect_to,我们在StackO

ruby-on-rails - 参数错误 : wrong number of arguments (1 for 2)

我是Rails、MVC和CRUD的新手,我正在尝试使用更新方法来更改帖子的投票数量。我的PostsController更新方法中有以下代码:defupdate@post=Post.find(params[:id])ifparams[:vote]=='up'@post.update_column(:ups=>@post[:ups]+1)elsifparams[:vote]=='down'@post.update_column(:downs=>@post[:downs]+1)endflash[:notice]="Thanksforvoting!Thishelpsusdetermineimp