sinatra

How do I test Pony emailing in a Sinatra app, using rspec?

♀尐吖头ヾ 提交于 2019-12-11 02:29:46
问题 I'm trying out email_spec, which says it supports Pony, but I'm not sure how I'd go about testing emails in a sinatra app. The examples in the readme show usages with rails ActionMailer , but not in Pony. Not precious about using email_spec, so any other ideas for testing emails using rspec in sinatra are welcomed =) 回答1: I ended up looking at the pony spec file, and stealing code from it to write my specs =) This is what I have: ./spec/spec_helper.rb def do_not_send_email Pony.stub!(:deliver

Reload A Div And Move Previous Content

时光怂恿深爱的人放手 提交于 2019-12-11 02:21:28
问题 I have an ERB document: <!DOCTYPE html> <html> <head> <script> scrollDown = function() { document.body.scrollTop = document.body.scrollHeight; } </script> </head> <body onload='scrollDown()'> <div id='2'> </div> <div id='target'> <%=@chat%> <!-- @chat is a variable from my ruby file --> </div> <form action="/addChat?n=<%=@name%>" method='post'> <input name='nchat' type='text' onload='this.focus' autofill='no' style='width:100%;height:10em;vertical-align:top'> <input type='submit'> </form> <a

Problems implementing ruby geocoder using Sinatra

谁说胖子不能爱 提交于 2019-12-11 02:05:11
问题 According to the ruby geocoder documentation (rubygeocoder.com), it's possible to use the geocoder gem with a Sinatra app, but I'm running into issues getting it to work and haven't been able to find any working examples or related stackoverflow issues either. I think the problem is due to the fact that it's a Sinatra app and not a full rails app. My Gemfile: source "https://rubygems.org" ruby '2.1.2' gem 'dotenv', '~> 0.10.0' gem 'pg', '~> 0.17.1' gem 'rack-flash3' gem "sinatra" gem

Sinatra - ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base

六眼飞鱼酱① 提交于 2019-12-11 01:20:43
问题 I've only been able to find rails answers to this question. Whenever I run rake db:migrate I am getting the aforementioned error. As far as I am aware, I have setup everything correctly so have no idea what's wrong. config/environment.rb ENV['SINATRA_ENV'] ||= "development" require 'bundler/setup' Bundler.require(:default, ENV['SINATRA_ENV']) configure :develpoment do set :database, 'sqlite3:db/database.db' end require './app' Rakefile require "./config/environment" require "sinatra

How do I go about setting up my Sinatra REST API on a server?

耗尽温柔 提交于 2019-12-11 00:37:35
问题 I'm an iOS developer primarily. In building my current app, I needed a server that would have a REST API with a couple of GET requests. I spent a little time learning Ruby, and landed on using Sinatra, a simple web framework. I can run my server script, and access it from a browser at localhost:4567 , with a request then being localhost:4567/hello , as an example. Here's where I feel out of my depth. I setup an Ubuntu droplet at DigitalOcean, and felt my way around to setting up all necessary

Sinatra on Passenger always fails on first attempt

感情迁移 提交于 2019-12-10 23:08:47
问题 I have a small Sinatra app I'm running on a shared hosting account using Passenger. However, the first time the app is accessed after a while, I get a Passenger error page saying the application could not be started. Usually because Sinatra could not be found. I am assuming this is just a normal delay from when a new instance is spawned. However, is there a way to delay trying to load Siantra until it Passenger has fully loaded? 回答1: I seem to have solved the issue by setting the GEMS_PATH

How to create a Rails-like before filter in Sinatra?

狂风中的少年 提交于 2019-12-10 22:16:20
问题 class Foo def do_before ... end def do_something ... Is there a way to run do_before method before each other method in the Foo class (like do_something )? It seems that the Sinatra before block runs before each HTTP request, which has nothing to do with this class. EDIT: As Michael pointed out in the comments, the only similar functionality that Rails offers is in the Controller. However, both Rails and Sinatra offer something similar to this functionality. 回答1: As iain pointed out in the

Testing an AJAX POST using Rack::Test - how to pass in data?

匆匆过客 提交于 2019-12-10 21:30:27
问题 I'm using Rack::Test to test my app and need to test the posting of data via AJAX. My test looks like: describe 'POST /user/' do include Rack::Test::Methods it 'must allow user registration with valid information' do post '/user', { username: 'test_reg', password: 'test_pass', email: 'test@testreg.co' }.to_json, {"CONTENT_TYPE" => 'application/json', "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"} last_response.must_be :ok? last_response.body.must_match 'test_reg has been saved' end end But at

Sinatra app not deploying to Heroku, rackup crashed

天涯浪子 提交于 2019-12-10 21:28:07
问题 config.ru require './app' run Sinatra::Application Gemfile source 'http://rubygems.org' gem 'heroku' gem 'sinatra' gem 'thin' Procfile web: bundle exec rackup config.ru -p $PORT Here are my heroku logs 2013-08-10T01:21:03.753984+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file' 2013-08-10T01:21:03.754180+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:250:in `start' 2013-08-10T01:21:03.754180+00

How to do a Sequel query with 'like'?

孤人 提交于 2019-12-10 19:24:48
问题 I'm trying to implement a form to search through the title of my posts. This is the controller code: post '/search' do @results = Post.all(:Title.like => "%#{params[:query]}%") erb :layout end This is the layout.erb code: <form action="/search" method="post"> <input type="text" name="query"/><br /> <input type="submit" /> </form> <% if @results %> <table> <%@results.each do |r|%> <tr valign="top"> <td><%=r.Title%></td> </tr> <%end%> </table> <% end %> I get an error saying 'undefined method