草庐IT

face_file_name

全部标签

ruby-on-rails - 验证失败 : Upload file has an extension that does not match its contents

我正在使用回形针gem上传文件。我的回形针gem版本是paperclip-4.1.1。上传文件时抛出Validationfailed:Uploadfilehasanextensionthatdoesnotmatchitscontents.我正在尝试上传xlsx文件。而且我已经在模型content_type中提到了这一点。validates_attachment_content_type:upload_file,:content_type=>%w(application/mswordapplication/vnd.ms-officeapplication/vnd.ms-excelappl

ruby-on-rails - `add_route' : Invalid route name, 已在使用中:'root' (ArgumentError)

我使用的是rails4.1.1和ruby​​2.1.1,我在设计方面遇到了问题,即我的路线。我以前用过很多次devise_for:usersget'pages/index'#RoutetoDeviseLoginPagedevise_scope:userdorootto:"devise/sessions#new"end#Directingtheuserafterloginauthenticated:userdoroot:to=>'pages#index'end但是我得到了错误`add_route':Invalidroutename,alreadyinuse:'root'(Argument

ruby-on-rails - 带@global gem 的 Ruby/RVM - bundle 运行失败,显示 `require' : cannot load such file — bundler (LoadError)

我学习了1个月的linux。当我尝试从MigratingfromMySQLtoPostgresonHeroku开始执行所有步骤时我遇到无法处理的错误。当我尝试从源代码安装mysqltopostgresgem时:$gitclonehttps://github.com/maxlapshin/mysql2postgres.git$cdmysql2postgres$bundleinstall$gembuildmysqltopostgres.gemspec$sudogeminstallmysqltopostgres-0.2.20.gem我在$bundleinstall上有一个错误:/home/f

ruby-on-rails - 使用 named_scope 获取行数

Rails专家:感谢另一位SO用户,我刚刚发现了named_scope。:)我想获取一组行的计数-即SELECTCOUNT(*)。此外,我希望仍然能够在调用中链接命名范围。这是命名范围的合法(尽管很奇怪)用法吗?named_scope:count,:select=>"COUNT(*)ascount_all"然后我可以做(例如):@foobar=Foobar.count.scope.scope.scope计数通过@foobar.first.count_all访问。(EditedtoaddressAllan'scomments)你可以这样做:@foobar=Foobar.scope.sco

ruby - Rspec——需要 stub File.open 在另一个文件中被调用

在我的测试中,我使用一些参数初始化了一个名为Package的新类。在这个类的初始化中,我打开了一个文件,该文件在我的远程机器上可用,但在本地通常不存在。我想知道如何在我的测试中stub该方法。我正在使用rspec和mocha。我试过类似的东西:File.stubs(:open).with(:file).returns(File.open("#{package_root}/test_files/test.yml"))在我的测试中初始化Package之前,我有这一行。我遇到了这个错误:unexpectedinvocation:File.open('package/test_files/te

ruby - 如何修复意外的 'sudo bundle install dir_name' ?

我不小心运行了sudobundleinstallsmtp_mail,现在我所有的gem都在我的Rails应用程序中这个名为smtp_mail的目录中。我不确定gem的默认位置?而且,我的Rails应用程序在启动时提示。有什么办法可以恢复原状吗? 最佳答案 经过一番谷歌搜索后,我找到了答案只需运行:sudobundleinstall--system然后您会将您的gem放回到它们适当的系统目录中。 关于ruby-如何修复意外的'sudobundleinstalldir_name'?,我们在S

ruby-on-rails - ruby rails : no such file to load -- openssl on RedHat Linux Enterprise

我正在尝试执行“rakedb:migrate”并收到错误消息“没有要加载的文件--openssl”。“openssl”和“openssl-devel”包都已安装。Debian或Ubuntu上的其他人似乎能够通过安装“libopenssl-ruby”来摆脱这种情况,这不适用于RedHat。有没有人遇到过这个问题并有解决方案? 最佳答案 升级到8.10后,我在Ubuntu上遇到了这个问题。Ubuntu的解决方案是sudoapt-get安装libopenssl-ruby 关于ruby-on-r

ruby-on-rails - 创建新的 Rails 3 项目时出错 : `require' : cannot load such file -- openssl (LoadError)

当我尝试创建一个新项目($railsnewfirst_app)时,它在创建目录结构后出现以下错误。......createvendor/plugins/.gitkeeprunbundleinstall/home/amit/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--openssl(LoadError)from/home/amit/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site

ruby - rbenv 和 bundler : "bad interpreter: No such file or directory"

我搞砸了我的配置。我正在运行Ubuntu14.04,当我尝试从一个项目转移到另一个项目时遇到了一些问题。我尝试卸载并重新安装rbenv,然后按照本指南安装了Ruby2.1.7:https://gorails.com/setup/ubuntu/14.04.现在,当我运行geminstallbundler时,没有任何反应,我无法安装任何gem。当我输入bundler或bundler-v我看到这个:/usr/local/bin/bundler:/usr/bin/ruby1.9.1:badinterpreter:Nosuchfileordirectory我花了很多时间试图解决这个问题,但我真的

ruby - Heroku 应用程序无法启动 - `require' : no such file to load -- sinatratestapp (LoadError)

我正在尝试使用bamboo-mri-1.9.2堆栈运行我的Heroku应用程序。当然,它在Ruby1.9.2上本地运行良好。但是在生产环境中,它在执行config.ru的启动过程中崩溃,如下所示:require'sinatratestapp'runSinatra::Application我的.gems文件:sinatra--version'>=1.0'应用程序本身为sinatratestapp.rb:require'rubygems'require'sinatra'get'/'do"HellofromSinatraonHeroku!"end这就是我在项目中得到的所有内容,并尝试在Her