草庐IT

show_date

全部标签

ruby-on-rails - 设计注销错误 - 找不到 UsersController 的操作 'show'

设计生成了以下代码以将用户注销:并且在执行rakeroutes时出现路由destroy_user_sessionDELETE/users/sign_out(.:format){:action=>"destroy",:controller=>"devise/sessions"}但是我收到一条错误消息:Theaction'show'couldnotbefoundforUsersController有什么想法吗? 最佳答案 路径是正确的,但如果你仔细观察,你会发现它不是GET请求而是DELETE请求,所以传递方法::delete%>编辑:

ruby-on-rails - rails 引擎 : rake routes show its routes but on rspec execution "No route matches" is thrown

我正在尝试测试我的应用程序正在使用的引擎内部的Controller。规范不在引擎中,而是在应用程序本身中(我试图在引擎中进行测试,但也遇到了问题)。我的引擎有以下routes.rb:Revision::Engine.routes.drawdoresources:steps,only:[]docollection{get:first}endend引擎正常挂载在应用routes.rb上:mountRevision::Engine=>"revision"当我运行rakeroutes时,在最后一行我得到:RoutesforRevision::Engine:first_stepsGET/step

Ruby Time#to_date() 方法返回错误的日期

我们使用的是Ruby1.9.3,我发现Time#to_date似乎是一个奇怪的Ruby错误Time.new(1).to_date在应返回0001年1月1日时返回0001年1月3日。我无意中发现了这个问题。似乎如果我调用.to_datetime.to_date,结果是正确的。我还发现了一些其他相关的怪异之处。请参阅下面的irb控制台输出。(请注意,我使用的是irb,而不是railsconsole,以确保我使用的只是Ruby,不是Rails的任何附加内容。)>>require"Time"=>true>>Time.new(1).to_date=>#>>Time.new(1).to_datet

ruby - MongoDB:无法从 BSON 类型 EOO 转换为 Date

我正在尝试使用聚合框架(使用ruby​​)并像这样投影日期:db['requests'].aggregate([{"$project"=>{_id:0,method:'$method',user:'$user',year:{'$year'=>'$timestamp'}}}])文档是这样的:{_id:ObjectId("5177d7d7df26358289da7dfd"),timestamp:ISODate("2013-04-12T03:58:05+00:00"),method:"POST",status:"200",inputsize:"874",outputsize:"4981",u

ruby - 在 Rails 中覆盖 "show"资源路由

resources:some_resource即有路由/some_resource/:id事实上,:idforsome_resource会一直保存在session中,所以我想重写路径/some_resource/:id使用/some_resource/my。或者我想用/some_resource/覆盖它并删除路径GET/some_resource/以进行索引操作。我怎样才能达到这两个目标? 最佳答案 在你的routes.rb中放置:get"some_resource"=>"some_resource#show"行前resources

ruby-on-rails - 为什么 Date.yesterday 也算作 Date.today?

我有以下模型和方法:classUserPriceDate.today)enddefself.yesterdaywhere(:purchase_date=>Date.yesterday)end为什么在我的表单上,如果我给日期选择字段:purchase_date1/4/2012(yesterday方法)它也算作今天(today方法),如果我给它1/5/2012(今天)它是零?附言我将Rails3.0.10与PostgreSQL结合使用。更新这是我的控制台返回:$railsconsole--sLoadingdevelopmentenvironmentinsandbox(Rails3.0.10

ruby-on-rails - rails ActiveAdmin : showing table of a related resource in the same view

当使用RailsActiveAdmingem显示资源时,我想显示另一个关联模型的表格。假设一个酿酒厂有很多:products。现在我想在Winery管理资源的show页面上显示关联的产品。我希望它是一个类似于我在Products资源的index上得到的表格。我让它工作了,但只能通过手动重新创建HTML结构,这很糟糕。是否有更简洁的方法来为关联资源的特定子集创建index表样式View?我有什么,有点糟透了:showtitle::namedo|winery|attributes_tabledorow:namerow(:region){|o|o.region.name}rows:prima

ruby-on-rails - 使用 Date::DAYNAMES 在 Rails 中显示一周中的几天列表

我无法在表单中显示一周中的几天列表。我遇到了错误undefinedmethod`Sunday'for#但是如果我只是显示,它会给我一个列表Sunday,Monday,Tuesday,etc...toSaturday我在这里做错了什么?谢谢 最佳答案 替换与 关于ruby-on-rails-使用Date::DAYNAMES在Rails中显示一周中的几天列表,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com

ruby - Date::today 未定义?

为什么只有Date类的某些方法没有显式加载:require'date'线?例如:irb(main):002:0>Date.todayNoMethodError:undefinedmethod`today'forDate:Classfrom(irb):2from/Users/mwlang/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in`'然后……irb(main):003:0>require'date'=>true导致...irb(main):004:0>Date.today=>#http://ruby-doc.org/stdlib-2.0/libdoc/

ruby-on-rails - Rails : Date. 今天 - 1.day

使用rails控制台,我只是被这个咬住了:假设今天是12月11日。Date.today-1.day#December10(nospaces)Date.today-1.day#December10(aspaceonbothsidesoftheminussign)Date.today-1.day#December11whaaaat?Date.today-5.days#Stilldecember11!有人能解释一下这是怎么回事吗?我有点担心这在代码中很容易被遗漏。关于如何对此进行编码还有其他建议吗? 最佳答案 您看到的差异是由ruby​​