Error when starting Sinatra: tried to create Proc object without a block
From what I can tell, and I've encountered this before, v1.2.5 of Sinatra is the problem. v1.2.3 doesn't do it, so try
gem install sinatra -v 1.2.3
to install the previous version, then add:
gem 'sinatra', '=1.2.3'
before the require
statement.
This is documented as an issue.
EDIT: Sinatra just bumped to a new version, 1.2.6, which fixes this problem. Use gem update sinatra
, followed by gem uninstall sinatra -v 1.2.5
to remove the old, buggy, version.
Proc throws error when used with do end
Your first code is interpreted as:
run(Proc.new) do |env|
...
end
and the block is is passed to run
instead of new
. The problem can be solved by doing:
run(Proc.new do |env|
...
end)
Why won't Sinatra work correctly?
Looks like it's a bug in sinatra: https://github.com/sinatra/sinatra/issues/258.
As a workaround, try the previous version of sinatra: gem install sinatra -v 1.2.3
, either in a new rvm gemset, or specify the version you want in your file with gem 'sinatra' '=1.2.3'
before your require sinatra
line.
Update:
Sinatra 1.2.5 (the version at fault) has been yanked and a new version released. Anyone getting this error can now just do gem update sinatra
and use the updated gem.
How to display sinatra error and other variables in minitest output
You can use puts last_response.errors
to show the Rack error messages for the last response.
Resolving Sinatra and HTTParty method name clashes
The get method is a class method.
Please try to the following, but I've not tried it out yet...
self.class.get
Sinatra with a Pure Ruby database
To take a leaf about of sinatra-redis's book, you can do something like this:
require 'sinatra'
require 'kirbybase'
helpers do
# Create a helper to allow easier access to settings.kirby
# Name it whatever you want
def kirby
settings.kirby
end
end
configure do
# Initialise kirby
set :kirby, KirbyBase.new
end
get '/' do
cars_tbl = kirby.get_table(:cars)
ferrari = cars_tbl.select { |r| r.recno == 9 }
"Car is #{ferrari}"
end
Heroku production issues with Sinatra app (Error R10)
Heroku dynamically assigns the port. You are starting the app on port 4567 when you call the run!
method in lines 85-97 of myapp.rb. You should be able to remove those three lines and use config.ru to start your app.
It you add the heroku gem to your Gemfile, you can remove the Procfile. Otherwise you should cahnge it start the app via backup:
web: bundle exec rackup config.ru -p $PORT
You could also add 'thin' to your Gemfile and use a Procfile like this
web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT
Related Topics
How to Build a Docker Image for a Ruby Project Without Build Tools
Errno::Enoent No Such File or Directory Rails 4
Can't Dup Nilclass on Association Methods
Bootstrap Modal in Ruby on Rails Not Working
How to Count Duplicates Hash Itens in Ruby 1.8.5 ( Sketchup Ruby API )
Convert Spreadsheet Column Index into Character Sequence
Rails: Chartkick Cummulative User Graph
How to Understand the #Dup and #Clone Operate on Objects Which Referencing Other Objects
Rails 404 Error for Stylesheet or JavaScript Files
Calling Instance Variables Without @
Integrate Shoes into Aptana Studio Radrails
Ruby: Why Are All Coordinates Getting Updated in an Array of Arrays
Undefined Method Error When Creating Delayed_Job Workers with Script/Delay_Job
Import CSV in Batches of Lines in Rails
Idiomatically Mock Openuri.Open_Uri with Minitest
Parsing Uris That Have Curly Braces, Uri::Invalidurierror: Bad Uri(Is Not Uri)
Why Does My Recursive Method from Helper Not Return Every Value