每当我运行Sinatra应用程序并尝试加载索引页面时,我都会收到Segmentation fault (core dumped)
和SystemStackError stack level too deep
。它会立即关闭应用服务器(Thin)。我无法弄清楚我哪里出错了,也找不到任何类似的错误。这似乎是Sinatra Assetpack的一个问题。当我注释掉layout.haml文件中的行时,我没有收到此错误。这是我的主要应用文件:
require 'sinatra'
require 'sinatra/activerecord'
require 'alphadecimal'
require 'sinatra/assetpack'
require 'less'
require 'haml'
#App files
require File.join(File.dirname(__FILE__), 'settings.rb') #Database
class UberUrlShortener < Sinatra::Base
set :root, File.dirname(__FILE__)
#Less.paths << "#{UberUrlShortener.root}/app/css"
register Sinatra::AssetPack
enable :inline_templates
assets do
serve '/js', from: 'app/js' # Default
serve '/css', from: 'app/css' # Default
serve '/images', from: 'app/images' # Default
# Add all the paths that Less should look in for @import'ed files
css :app, '/css/app.css', [
# '/css/bootstrap.css', # bootstrap.less
'/css/*.css',
'/css/*.min.css'
]
js :app, '/js/app.js', [
'/js/*.js'
]
css_compression :simple
js_compression :jsmin
end
#Routes Controller
get '/' do
haml :index
end
post '/' do
@short_url = ShortenedUrl.find_or_create_by_url(params[:url])
if @short_url.valid?
haml :success
else
haml :index
end
end
get '/:shortened' do
short_url = ShortenedUrl.find_by_shortened(params[:shortened])
redirect short_url.url
end
run! if app_file == $0
end
#Model. Later could be seperate file
class ShortenedUrl < ActiveRecord::Base
validates_uniqueness_of :url
validates_presence_of :url
validates_format_of :url, :with => URI::regexp(%w(http))
def shorten
self.id.alphadecimal
end
def self.find_by_shortened(shortened)
find(shortened.alphadecimal)
end
end
这是我的index.haml文件:
%form(action="/" method="POST")
%label(for="url")
%input(type="text" name="url" id="url")
%input(type="submit" value="Shorten")
-if @short_url.present? && !@short_url.valid?
%p Invalid URL: #{@short_url.url}
这是我的layout.haml文件:
!!!
%html
%head
%meta{:charset => 'utf-8'}
%title Uber URL Shortener
%meta{:name => 'description', :content => 'URL Shortner for Uber Digital Agency'}
%meta{:name => 'author', :content => 'Cody Littlewood'}
:plain
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
/Le styles
!=css :app
!=js :app
%body= yield
这是我的Gemfile:
source 'https://rubygems.org'
gem "sinatra", "~> 1.4.3", :require => 'sinatra/base'
gem 'thin', '~> 1.5.1' #decide on
gem 'pg', '~> 0.16.0'
gem 'alphadecimal', '1.1.2'
gem 'sinatra-assetpack', '~> 0.2.8'
gem 'haml', '~> 4.0.3'
gem 'less', '~> 2.3.2'
gem 'json', '~> 1.8.0'
gem 'therubyracer', '~> 0.11.4'
使用debug运行时出现错误:
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
./views/index.haml:-5: warning: instance variable @haml_buffer not initialized
./views/index.haml:5: warning: instance variable @short_url not initialized
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @silent not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @trace not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @silent not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @trace not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @silent not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @trace not initialized
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/engines/simple.rb:4: warning: ambiguous first argument; put parentheses or even spaces
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/engines/sqwish.rb:11: warning: assigned but unused variable - e
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/engines/uglify.rb:6: warning: assigned but unused variable - e
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `SystemStackError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/uri/common.rb:150 - stack level too deep
Exception `SystemStackError' at /home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1087 - stack level too deep
Segmentation fault (core dumped)
答案 0 :(得分:1)
通过删除我的主应用程序文件中资产块中的第二个参数来修复,该文件告诉Sinatra Assetpack应该在哪里提供css和js文件。它在宝石中创造了一场冲突。代码现在看起来像这样并且运行没有错误:
css :app, [
# '/css/bootstrap.css', # bootstrap.less
'/css/*.css',
'/css/*.min.css'
]
js :app, [
'/js/*.js'
]