草庐IT

In-source

全部标签

ruby-on-rails - Rails 导入 CSV 错误 : invalid byte sequence in UTF-8

尝试在我的Rails应用程序中导入CSV文件时,出现错误UTF-8中的无效字节序列。一切正常,直到我添加了一个gsub方法来将其中一个CSV列与我的数据库中的一个字段进行比较。当我导入CSV文件时,我想检查每一行的地址是否包含在特定客户端的不同地址数组中。我有一个带有alt_addresses属性的客户端模型,其中包含客户端地址的几种不同可能格式。然后我有一个引用模型(如果您熟悉本地SEO,您就会知道这个术语)。引用模型没有地址字段,但它有一个nap_correct?字段(NAP代表“姓名”、“地址”、“电话号码”)。如果CSV行的名称、地址和电话号码与我在该客户的数据库中拥有的相同,

ruby-on-rails - rails 生成 rspec :install config/environments/development. rb:1:in `<top (required)>': 未定义方法 `configure'

首先,这是我的版本:Greg-Nowickis-MacBook-Pro:sample_appGreg_Nowicki$ruby-vruby2.0.0p451(2014-02-24revision45167)[x86_64-darwin13.1.0]Greg-Nowickis-MacBook-Pro:sample_appGreg_Nowicki$rails-vRails4.0.4我正在学习HartlRails教程并安装rspec进行测试。我已将gem'rspec-rails'添加到我的gemfile中,当我运行railsgeneraterspec:install时,这就是我得到的:Gre

ruby-on-rails - Rails 新手 : Recommendations for error handling in controller

抱歉,如果问题很明显,我才刚刚开始使用Rails。我现在在几个Controller方法中有以下代码:respond_todo|format|if@project.saveformat.html{redirect_to(edit_project_url(@project),:notice=>'#{user.name}addedto#{role}.')}format.jselseformat.html{render:action=>"edit"}format.js#...endend那么问题来了,对于所有方法中的错误,最好的方法是什么?是否建议我使用save!并在rescue_action

ruby : How can I detect/intelligently guess the delimiter used in a CSV file?

我需要能够确定我的Ruby项目中的csv文件中使用了哪个分隔符(逗号、空格或分号)。我知道,csv模块中的Python中有一个Sniffer类,可用于猜测给定文件的分隔符。Ruby中有类似的东西吗?非常感谢任何形式的帮助或想法。 最佳答案 看起来py实现只检查几种方言:excel或excel_tab。因此,仅检查","或"\t"的简单实现是:COMMON_DELIMITERS=['","',"\"\t\""].freezedefsniff(path)first_line=File.open(path).firstreturnunle

ruby - "string literal in condition"是什么意思?

每当我尝试运行该程序时,都会弹出一条错误消息“条件字符串文字(第10行)”。我做错了什么?puts"Welcometothebestcalculatorthereis.Wouldyouliketo(a)calculatetheareaofageometricshapeor(b)calculatetheequationofaparabola?Pleaseenteran'a'ora'b'togetstarted."response=gets.chompifresponse=="a"or"A"puts"ok."elsifresponse=="b"or"B"puts"awesome."else

ruby-on-rails - Rails 和 MQTT : Subscribe to topic in background at server startup?

我想在服务器启动时在我的Rails应用程序中订阅一个mqtt主题,并保持订阅始终处于事件状态和运行状态。我正在使用这个mqttgem进行mqtt通信:https://github.com/njh/ruby-mqtt这是我现在拥有的:在application.rb中:config.after_initializedomqttSub=BackgroundMQTT.newmqttSub.runend后台MQTT类:classMQTTSubscriberdefrunThread.newdoMQTT::Client.connect(:host=>'localhost',:port=>1883,)

ruby-on-rails - 脚本/服务器 custom_require.rb :36:in `require' : cannot load such file -- test/unit/error (LoadError)

我有一个基于1.8.7构建的应用程序,我正尝试在1.9.3的系统上启动它当我运行脚本/服务器时,我得到:/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--test/unit/error(LoadError)from/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'我的服务器脚本如下所示:#!/usr/bin/envrubyrequireFile.expand_path('../.

ruby-on-rails - Rails 设计 : "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.."

我已经安装了DeviseonRails4.2.0,一切似乎都在工作,我使用了以下指南:http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/我的设计模块是:devise:database_authenticatable,:registerable,:confirmable,:recoverable,:rememberable,:trackable,:validatable,:omniauthable唯一的问题是,如果我尝试通过转到注册页面创建一个新帐户,然后在输入我的电子邮

ruby , `match' : invalid byte sequence in UTF-8

我对UTF-8编码有一些问题。我在这里阅读了一些帖子,但它仍然无法正常工作。这是我的代码:#!/bin/envruby#encoding:utf-8defdeterminefile=File.open("/home/lala.txt")file.eachdo|line|puts(line)type=line.match(/DOG/)puts('aaaaa')iftype!=nilputs(type[0])breakendendend这是我文件的前3行:;?lalalalal60000065535-1362490443-0000006334-0000018467-0000000041en

jquery - Ruby 1.9.1、Rails 2.3.2 和 jrails 0.4 出现 "rescue in const_missing"错误

我最近开始了一个项目,团队决定我们希望使用jQuery而不是Prototype/Scriptaculous来满足我们的javascript需求。我们设置了我们的项目,并开始切换。插件已安装viatheseinstructions,一切都按计划进行。不久之后,当尝试运行“./script/server”时,我们收到以下错误:=>Rails2.3.2applicationstartingonhttp://0.0.0.0:3000/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/depende