sinatra

Running Ruby Sinatra inside a Docker container not able to connect (via Mac host) or find commands (in different scenario)?

前提是你 提交于 2019-12-04 19:55:58
问题 I've tried two forms of Dockerfile to get a simple Ruby/Sinatra app running, and in both scenarios it fails for different reasons (I'll explain both in a moment). Effectively I want to access the Sinatra web server from my host (Mac OS X using Boot2Docker). The app structure is: . ├── Dockerfile ├── Gemfile ├── app.rb ├── config.ru The contents of the files are: Dockerfile Version 1... FROM ruby RUN mkdir -p /app WORKDIR /app COPY Gemfile /app/ RUN bundle install --quiet COPY . /app EXPOSE

Using Sinatra and jQuery without redirecting on POST

≡放荡痞女 提交于 2019-12-04 19:42:20
I am trying to use jQuery to submit a form to my Sinatra app, but when POSTing via the AJAX, the Sinatra app is displaying a blank page. I would like it to stay on the same page, and update the content I have specified in the javascript. Here is my code, stripped down: post '/register' do register( params ) end get '/register' do haml :register end And here is my javascript in the haml file: :javascript $(function() { $("button#submit").click(function(){ $.ajax({ type: "POST", url: "/register", data: $('form.register').serialize(), success: function(){ $("#message").html("Successfully

How can I test helpers blocks in Sinatra, using Rspec?

孤街醉人 提交于 2019-12-04 17:54:09
问题 I'm writing a sinatra app and testing it with rspec and rack/test (as described on sinatrarb.com). It's been great so far, until I moved some rather procedural code from my domain objects to sinatra helpers. Since then, I've been trying to figure out how to test these in isolation ? 回答1: maybe this can help you some way http://japhr.blogspot.com/2009/03/sinatra-innards-deletgator.html 回答2: I test my sinatra helpers in isolation by putting the helper methods within its own module. Since my

Sessions in Sinatra using Facebook authentication

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:44:27
I'm very new to ruby & Sinatra and I have a basic question: The app I'm trying to build will use Facebook as it's sole method of authenticating users into the app. I want to store a local users table which will contain only the facebook uid along with some user preferences. I have looked at a couple of gems which allow me to authenticate against the facebook API, however I am unsure how to control sessions within my application once I have established the user is valid. I have been using the koala gem for talking to facebook, and I have also seen the sinatra-session gem for running the session

how to make a sinatra app run in rails 4?

依然范特西╮ 提交于 2019-12-04 17:03:21
I have a Sinatra app and I'd like to start building new functionality in Rails while still supporting the existing Sinatra functionality. I've tried the following strategies: sinatra's rackup routes some requests to rails and some to sinatra sinatra's rackup includes rails rails' rackup includes sinatra. Many of my searches resulted in rails 3, not 4. Additionally, does Rails have to generate the db versus using one that Sinatra was using (in this case, the Sequel gem to access Sqlite3.) In general the errors I was getting were about gems and paths. (Although I did rebundle and try different

How can I send binary data from Sinatra?

橙三吉。 提交于 2019-12-04 16:23:51
问题 I want to send binary data from a Sinatra application so that the user can download it as a file. I tried using send_data but it gives me an undefined method 'send_data' How could I achieve this? I could write the data to a file and then use send_file but I would rather avoid doing this. 回答1: you can just return binary data: get '/binary' do content_type 'application/octet-stream' "\x01\x02\x03" end 回答2: I did it like this: get '/download/:id' do project = JSON.parse(Redis.new.hget('active

rspec clean database before running

可紊 提交于 2019-12-04 15:19:20
I'm using RSpec in a Sinatra project. I'm testing a model which runs an after_find hook to initialize some values. I need to wipe the database before every run, and after some searching around, my spec helper file looks like this: require "pry" require "factory_girl_rails" require "rspec-rails" FactoryGirl.find_definitions ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) RSpec.configure do |config| config.use_transactional_fixtures = true end I'm getting the following error: undefined method `use_transactional_fixtures=' for #<RSpec::Core::Configuration

Sinatra - terminate server from request

◇◆丶佛笑我妖孽 提交于 2019-12-04 14:46:02
I want to be able to terminate a Sinatra app from a request, e.g. with the following route: post '/terminate' do Thread.current.kill end Implementing it like this is a bit abrupt. I'd rather the request completed, returned an HTTP OK message, and then Sinatra shut down gracefully. Is there a hook to do this? Edit: My application is a lightweight mock server used for receiving webhook notifications. I will be using multiple servers like this on the same machine (different ports), so need to avoid any global methods of starting/stopping. My requirement is driven by the fact that each server must

Ruby w/ Sinatra: Could I have an example of a jQuery AJAX request?

家住魔仙堡 提交于 2019-12-04 14:16:57
问题 %a{:href => "/new_game?human_is_first=true", :remote => "true"} %span Yes Above is my link. Just wondering how to handle this. I need to be able to execute some javascript. Below is a .js.erb file from back when I using rails. $('.welcome_container').fadeOut(500, function(){ $( '.shell' ).html( "<%= escape_javascript( render( :partial => "board/board" ) ) %>" ); $('.board_container').fadeIn(500); }); So, my question is, Once /new_game is called in app.rb, I want to be able to send some

Sinatra + Heroku + Datamapper deploy issues with dm-sqlite-adapter

*爱你&永不变心* 提交于 2019-12-04 13:06:44
问题 For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres here. Note, that this happens when I open any URL - not during the git push itself. I built a default facebook app. The Gemfile: source :gemcutter gem "foreman" gem "sinatra" gem "mogli" gem "json" gem "httparty" gem "thin" gem "data_mapper" gem "heroku" group :production do gem "pg" gem "dm-postgres-adapter" end group :development, :test do gem "sqlite3" gem "dm-sqlite-adapter" end Datamapper setup