草庐IT

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

ruby - Rubocop 错误 'Class definition is too long ruby'

我收到rubocop错误“类定义太长。[236/100]'。我的类(class)如下所示:classSomeClassNameincludeHelperModuleattr_accessor:aaa,:bbb,:ccc....methods.....end可能会出现什么问题?rubocop文档ClassLength说“一个类(class)的长度超过了某个最大值”。什么意思? 最佳答案 是的,这是因为rubucop认为整体线路太多。我同意类(class)不应该太长,但认为最终应该由以下因素决定:类(class)是否有单一职责,方法是否

ruby-on-rails - Mac OS X 山狮 "Rails is not currently installed on this system."

我正在全新安装OSXMountainLion。我通过以下方式安装了Rails:sudogeminstallrails一切似乎都安装正确,但是当我键入rails命令(railss、rails-v等)时,我收到此错误:Railsisnotcurrentlyinstalledonthissystem.Togetthelatestversion,simplytype:$sudogeminstallrailsYoucanthenrerunyour"rails"command.'whichrails'的结果是/usr/bin/rails我认为这是一个路径问题,也许是,但我可以看到/usr/bin是

ruby - RVM + Zsh "RVM is not a function, selecting rubies with ' rvm 使用.. .' will not work"

首先我要说我不是命令行专家,所以我真的几乎不知道自己在做什么。我无法让RVM和oh-my-zsh一起玩得很好。我尝试了几种不同的解决方案,其中一些是在SO上发布的,但我发现似乎没有任何解决方案可以解决问题。最初,其他人在我的机器上安装了RVM。后来我自己设置了oh-my-zsh,记得当时遇到了很多麻烦。除了这两行,我的.zhsrc文件是完全默认的exportPATH=$HOME/bin:/usr/local/bin:/usr/local/rvm/bin:$PATH#prettysurethislinedoesnothing,althoughI'veseenthisfixaround#s

ruby 公案 : test_nil_is_an_object

我最近尝试使用这个工具来提高我的Rails技能:http://github.com/edgecase/ruby_koans但我无法通过一些测试。此外,我不确定我是否正确地做了一些事情,因为目标只是通过测试,有很多方法可以通过它,我可能正在做一些不符合标准的事情。有没有办法确认我做的事情是否正确?具体例子:在about_nil中,deftest_nil_is_an_objectassert_equal__,nil.is_a?(Object),"UnlikeNULLinotherlanguages"end它是告诉我检查第二个子句是否等于一个对象(所以我可以说nil是一个对象)或者只是把as

ruby - 安装 ruby​​racer 时出现错误 "invalid gem: package is corrupt"

尝试在OSX10.9上安装therubyracer时,使用以下命令:$geminstalltherubyracer-v'0.12.0'我得到错误:ERROR:Errorinstallingtherubyracer:invalidgem:packageiscorrupt,exceptionwhileverifying:undefinedmethod`path2class'for#(NoMethodError)in/Users/doved/.rvm/gems/ruby-2.0.0-p353/cache/therubyracer-0.12.0.gemXCode开发者工具已安装,我已尝试删除缓

ruby - 大多数方法中的 "This is a stub, used for indexing"?

我正在研究cursesgem的curses.rb,我发现它无处不在:defattrset(attrs)#Thisisastub,usedforindexingend#bkgdset(ch)##Manipulatethebackgroundofthecurrentwindow#withcharacterInteger+ch+##seealsoCurses.bkgdsetdefbkgdset(ch)#Thisisastub,usedforindexingend#bkgd(ch)##Setthebackgroundofthecurrentwindow#andapplycharacterInt

ruby-on-rails - slim 的模板 : Is it possible to put two elements on the same line?

我经常想嵌套元素,比如下面的导航:ullia(href="#")linkNamelia(href="#")linkNamelia(href="#")linkName是否可以将li和a放在同一行?像li>a这样的语法会很好。 最佳答案 我相信你可以做这样的事情ulli:ahref="#"Link1li:ahref="#"Link2参见内嵌标签:http://rdoc.info/gems/slim/file/README.md#Inline_tags 关于ruby-on-rails-slim

ruby - 在 Ruby 中使用 to_enum 创建可枚举对象有什么好处?

为什么要在Ruby中使用to_enum方法而不是直接使用对象来创建对对象的代理引用?我想不出任何实际用途,试图理解这个概念以及有人可能会在哪里使用它,但我看到的所有例子似乎都很微不足道。例如,为什么使用:"hello".enum_for(:each_char).map{|c|c.succ}代替"hello".each_char.map{|c|c.succ}我知道这是一个非常简单的例子,有人有任何现实世界的例子吗? 最佳答案 如果没有提供block,大多数接受block的内置方法将返回一个枚举器(如示例中的String#each_ch

ruby-on-rails - ruby rails : How would i stay on the same page if the post is not saved?

defcreate@addpost=Post.newparams[:data]if@addpost.saveflash[:notice]="Posthasbeensavedsuccessfully."redirect_toposts_pathelseflash[:notice]="Postcannotbesaved,pleaseenterinformation."endend如果帖子未保存,则会重定向到http://0.0.0.0:3000/posts,但我需要留在页面上,带有文本输入字段,以便用户可以输入数据。后模型classPosttruevalidates:content,:pr