标签: ruby

Heroku上的"bin/rails:没有这样的文件或目录"w/Ruby 2&Rails 4

在遵循Michael Hartl的Ruby on Rails教程的Rails 4 Beta版本时,我的应用程序无法在Heroku上启动,但在本地运行良好.检查显示以下错误:bundle exec rails serverheroku logs -t

$ heroku[web.1]: State changed from crashed to starting
$ heroku[web.1]: Starting process with command `bin/rails server 
-p 33847 -e $RAILS_ENV`
$ app[web.1]: bash: bin/rails: No such file or directory
$ heroku[web.1]: Process exited with status 127
$ heroku[web.1]: State changed from starting to crashed
$ heroku[web.1]: Error R99 (Platform error) -> Failed to launch the 
dyno within 10 seconds
$ heroku[web.1]: Stopping process with …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails heroku ruby-2.0 ruby-on-rails-4

57
推荐指数
3
解决办法
3万
查看次数

测试变量是否等于两个值中的任何一个

我想测试是a等于1 还是 2

我可以

a == 1 || a == 2
Run Code Online (Sandbox Code Playgroud)

但这需要重复a(这对于较长的变量会很烦)

我想做类似的事情a == (1 || 2),但显然这不会奏效

我能做到[1, 2].include?(a),这并不坏,但让我觉得有点难以阅读

只是想知道如何使用惯用的红宝石

ruby

56
推荐指数
5
解决办法
2万
查看次数

如何在Mac OS X Lion中安装Ruby 1.9.3?

我正在尝试安装Ruby 1.9.3但是遇到了问题.我安装了RVM,然后键入:

rvm install 1.9.3
Run Code Online (Sandbox Code Playgroud)

输出说:

ERROR: Error running ' ./configure....
Run Code Online (Sandbox Code Playgroud)

日志说:

configure: WARNING: unrecognized options: --with-libyaml-dir 
checking build system type... x86_64-apple-darwin11.2.0 
checking host system type... x86_64-apple-darwin11.2.0 
checking target system type...x86_64-apple-darwin11.2.0 
checking whether the C compiler works... no
configure: error: in `/Users/myuser/.rvm/src/ruby-1.9.3-p0':
configure: error: C compiler cannot create executables See `config.log' for more details
Run Code Online (Sandbox Code Playgroud)

我从App Store下载了新的XCode并安装了它.

ruby macos osx-lion

56
推荐指数
6
解决办法
5万
查看次数

使用Live Reload和Jekyll

我开始使用Jekyll静态站点生成器,我想使用Live Reload.我知道Jekyll有一个生成器和服务器命令,Live Reload可以运行各种编译器和自定义命令.如何配置这些协同工作?

ruby jekyll

56
推荐指数
8
解决办法
2万
查看次数

如何在Rails控制器中返回HTTP 204

这似乎是基本的,但我是Ruby/Rails的初学者.我需要简单地在控制器中返回HTTP 204.将

respond_to do |format|
  format.html  
end
Run Code Online (Sandbox Code Playgroud)

返回204?

ruby ruby-on-rails

56
推荐指数
3
解决办法
3万
查看次数

在Ruby中获取当前目录的父目录

我知道我可以通过获取当前目录

$CurrentDir = Dir.pwd
Run Code Online (Sandbox Code Playgroud)

当前目录的父目录怎么样?

ruby directory

56
推荐指数
4
解决办法
3万
查看次数

检查红宝石中的字符长度

我陷入了另一种情况:我们的用户输入要存储在变量中的文本.该文本的条件是它只允许输入25个字符,现在我必须写一个正则表达式来检查条件,请帮助我解决这个问题.

ruby string

56
推荐指数
3
解决办法
12万
查看次数

如何使用bundler重新安装gem

我做了一个bundle show并获得了一个gem目录的完整路径.

不幸的是,我删除了目录rm -r gem_path.然后我的rails应用程序不再工作了.如果我尝试启动服务器或启动rails控制台,则会输出以下错误:

<class:Application>:未初始化的常量MyAPP::Application::Gem(NameError)

我该怎么做才能还掉它?

我试图bundle installbundle update希望强制捆绑搜索gem并将其安装回来,但是没有用.

我也尝试删除Gemfile.lock并运行bundle install.什么都没有改变,同样的错误.

有问题的宝石就是可以作为标记.

ruby rubygems bundler

56
推荐指数
7
解决办法
8万
查看次数

使用send_file从Amazon S3下载文件?

我的应用程序中有一个下载链接,用户应该能够下载存储在s3上的文件.这些文件可以在网址上公开访问,看起来像

https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png
Run Code Online (Sandbox Code Playgroud)

下载链接在我的控制器中执行操作:

class AttachmentsController < ApplicationController
  def show
    @attachment = Attachment.find(params[:id])
    send_file(@attachment.file.url, disposition: 'attachment')
  end
end
Run Code Online (Sandbox Code Playgroud)

但是当我尝试下载文件时出现以下错误:

ActionController::MissingFile in AttachmentsController#show

Cannot read file https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png
Rails.root: /Users/user/dev/rails/print

Application Trace | Framework Trace | Full Trace
app/controllers/attachments_controller.rb:9:in `show'
Run Code Online (Sandbox Code Playgroud)

该文件肯定存在,可以在错误消息的URL中公开访问.

如何允许用户下载S3文件?

ruby ruby-on-rails amazon-s3 ruby-on-rails-3 ruby-on-rails-3.2

56
推荐指数
5
解决办法
4万
查看次数

具有条件的数组的第一个元素

是否有更短的方法来找到满足某些条件的数组中的第一个元素:

my_array[ my_array.index {|x| x.some_test} ]
Run Code Online (Sandbox Code Playgroud)

ruby arrays

56
推荐指数
2
解决办法
3万
查看次数