jjzjj

new-window

全部标签

ruby-on-rails - 设计中的 ArgumentError::RegistrationsController#new 错误的参数数量(2 代表 0..1)

我在关注RyanbatesRailsCast的devise和omniauth(第235集-devise-and-omniauth-revised)。当我尝试使用Twitter登录时,标题中不断出现错误。defself.new_with_session(params,session)ifsession["devise.user_attributes"]new(session["devise.user_attributes"],without_protection:true)do|user|user.attributes=paramsuser.valid?end完整跟踪:C:/Ruby20

ruby-on-rails - 从 ActiveAdmin has_many 表单助手中删除 "Add new"按钮

我在事件管理员编辑页面中有嵌套资源,但我只想允许管理员编辑现有资源的内容,而不是添加新的嵌套资源。我的代码看起来像这样:formdo|f|f.inputsdof.input:authorf.input:contentf.has_many:commentsdo|comment_form|comment_form.input:contentcomment_form.input:_destroy,as::boolean,required:false,label:'Remove'endendf.actionsend但它在输入下添加了“添加新评论”按钮。我怎样才能禁用它,并只为主窗体保留f.ac

ruby - 什么是 "Class.new"?

我不明白下面这段代码中的Sheep=Class.new部分。moduleFenceSheep=Class.newdodefspeak"Bah."endendenddefcall_sheepFence::Sheep.new.speakend它到底在做什么? 最佳答案 根据文档,Class.newCreatesanewanonymous(unnamed)classwiththegivensuperclass(orObjectifnoparameterisgiven).此外,Youcangiveaclassanamebyassigning

ruby - 减少数组时使用 Hash.new 作为初始值

我有一个这样的数组[1,1,2,3,3,3,4,5,5]我想计算每个数字出现的次数,我正在尝试这样做[1,1,2,3,3,3,4,5,5].reduce(Hash.new(0)){|hash,number|hash[number]+=1}问题是当我尝试运行它时出现以下错误NoMethodError:undefinedmethod`[]='for1:Fixnumfrom(irb):6:in`blockinirb_binding'from(irb):6:in`each'from(irb):6:in`reduce'from(irb):6我能像这样设置初始值吗,还是我弄错了?

ruby - 错误 : Failed to build gem native extension on Windows

我在安装“redcarpet”gem时遇到以下错误。它在我friend的机器上安装没有问题。(我想安装它来运行yard)ruby版本:1.9.3命令输出:D:\Learning\Common_POM_FW\SampleProjects>yard[error]:Missing'redcarpet'gemforMarkdownformatting.Installitwith`geminstallredcarpet`D:\Learning\Common_POM_FW\SampleProjects>geminstallredcarpetTemporarilyenhancingPATHtoinc

ruby - 从 Ruby 连接到适用于 Windows Phone 8 的 Microsoft 推送通知服务

我们正在开发一个需要推送通知的WP8应用程序。为了测试它,我们使用CURL命令行运行推送通知POST请求,确保它实际连接,使用客户端SSL证书进行身份验证并发送正确的数据。我们确实知道,当我们收到对设备的推送时,这项工作是有效的。这是我们一直用于测试目的的CURL命令:curl--certclient_cert.pem-v-H"Content-Type:text/xml"-H"X-WindowsPhone-Target:Toast"-H"X-NotificationClass:2"-XPOST-d"MytitleMysubtitle"https://db3.notify.live.ne

ruby - 在 Windows 7 上运行 Jekyll

我在Windows7上运行Jekyll时遇到问题。当我运行时jekyll出现以下错误C:\temp\jekyll\kouphax.github.com>jekyllConfigurationfromC:/temp/jekyll/kouphax.github.com/_config.ymlBuildingsite:C:/temp/jekyll/kouphax.github.com->C:/temp/jekyll/kouphax.github.com/_siteunit-testingYouaremissingalibraryrequiredforTextile.Pleaserun:$[s

ruby-on-rails - rails : Pass Parameters to New Controller during 'redirect_to'

我正在使用RyanBates的RailsCastonWickedWizardForms创建一个多步骤表单。我没有定义current_user方法(不使用身份验证gem)-因此,我试图在redirect_to期间传递user.id参数-不幸的是,我似乎无法让它工作。任何帮助表示赞赏!我的用户Controller创建方法defcreate@user=User.new(params[:user])respond_todo|format|if@user.saveformat.html{redirect_tocontroller:'user_steps',id:'user.id'}#format

ruby - 是否有与 'new' 哈希语法等效的 Ruby Hash#to_s?

Hash#to_s(inspect的别名)始终以1.8哈希样式输出数据:{key:"value"}.to_s=>"{:key=>\"value\"}"是否有任何核心方法将其序列化为1.9哈希样式?{key:"value"}.to_s=>"{key:\"value\"}"我在已知数据上使用它进行代码重构;由于Ruby倾向于实现所有内容,我希望我只是找错了地方。当然,你可以用丑陋的方式破解它"{"+my_hash.to_a.map{|pair|pair[0].to_s+":"+pair[1].inspect}*",\n")+"}"但我希望有一个经过单元测试且完全正确的核心方法。

ruby - 为什么 Date.new 不调用初始化?

我想创建Date的子类。一个正常的、健康的、年轻的ruby​​ist,没有被Date的实现的特殊性所伤害,会以下面的方式来解决这个问题:require'date'classMyDate然后继续以最预期的方式使用它......require'my_date'mdt=MyDate.new(2012,1,28)putsmdt.to_s...只是因为Date::new方法实际上是Date::civil的别名,它永远不会调用初始化。在这种情况下,最后一段代码打印“2012-01-28”而不是预期的“2012-12-25”。亲爱的Ruby社区,这是什么鬼?new别名是否有一些很好的理由,以便它忽略