sinatra

AngularJS POSTs empty requests?

天大地大妈咪最大 提交于 2020-01-02 15:39:32
问题 I'm a newbie in AngularJS and I've faced an issue when I try to make a POST request with AngularJS and it POSTs no parameters with it. I use Sinatra as a RESTful interface. That's how my Sinatra backend looks: post '/layer/:layer_id' do @layer = PageLayer.where(id: params[:layer_id]).first @layer.content = params[:content] @layer.save end If try to POST with Postman chrome extension - it works! Sinatra saves the content properly. So I'm sure that the backend works as it should. That's how my

AngularJS POSTs empty requests?

十年热恋 提交于 2020-01-02 15:39:17
问题 I'm a newbie in AngularJS and I've faced an issue when I try to make a POST request with AngularJS and it POSTs no parameters with it. I use Sinatra as a RESTful interface. That's how my Sinatra backend looks: post '/layer/:layer_id' do @layer = PageLayer.where(id: params[:layer_id]).first @layer.content = params[:content] @layer.save end If try to POST with Postman chrome extension - it works! Sinatra saves the content properly. So I'm sure that the backend works as it should. That's how my

How do I tell Sinatra what environment (development, test, production) it is?

穿精又带淫゛_ 提交于 2020-01-02 03:39:08
问题 (Disclaimer: New to deploying Sinatra on Heroku.) I have seen http://www.sinatrarb.com/configuration.html and it tells me to set :environment, :production . My question is, how can I specify it to do: "when in Heroku, set environment as production, else stay in test/development." Also, even after putting the line set :environment, :production , I don't think it is working because when I try to rackup the app locally, it's still running (when I know (or I think I know) that it shouldn't

Stubbing RestClient response in RSpec

江枫思渺然 提交于 2020-01-01 08:27:49
问题 I have the following spec... describe "successful POST on /user/create" do it "should redirect to dashboard" do post '/user/create', { :name => "dave", :email => "dave@dave.com", :password => "another_pass" } last_response.should be_redirect follow_redirect! last_request.url.should == 'http://example.org/dave/dashboard' end end The post method on the Sinatra application makes a call to an external service using rest-client. I need to somehow stub the rest client call to send back canned

Can I have Sinatra / Rack not read the entire request body into memory?

五迷三道 提交于 2020-01-01 06:52:33
问题 Say I have a Sinatra route ala: put '/data' do request.body.read # ... end It appears that the entire request.body is read into memory. Is there a way to consume the body as it comes into the system, rather than having it all buffered in Rack/Sinatra beforehand? I see I can do this to read the body in parts, but the entire body still seems to be read into memory beforehand. put '/data' do while request.body.read(1024) != nil # ... end # ... end 回答1: You cannot avoid this in general without

Can I have Sinatra / Rack not read the entire request body into memory?

独自空忆成欢 提交于 2020-01-01 06:52:17
问题 Say I have a Sinatra route ala: put '/data' do request.body.read # ... end It appears that the entire request.body is read into memory. Is there a way to consume the body as it comes into the system, rather than having it all buffered in Rack/Sinatra beforehand? I see I can do this to read the body in parts, but the entire body still seems to be read into memory beforehand. put '/data' do while request.body.read(1024) != nil # ... end # ... end 回答1: You cannot avoid this in general without

best/most elegant way to share objects between a stack of rack mounted apps/middlewares?

Deadly 提交于 2020-01-01 05:23:06
问题 What is the best idiom to share an object between rack mounted applications/middlewares? For example, this config.ru has two Sinatra apps mapped to differents endpoints: class App1 < Sinatra::Base # ... end class App2 < Sinatra::Base # ... end map '/app1' do run App1 end map '/app2' do run App2 end Now if these two applications need to share an object, be it a database connector or any other object, what would be the best idiom for this? I see basically two options: 1- Create a constant at

Static page routing in Sinatra (Ruby)

China☆狼群 提交于 2020-01-01 04:18:06
问题 You can serve static files with Sinatra by placing them in public/ (by default) -- I have an index.html in there at the moment, but how can I make the root point to that file without having to parse it as a template? To be clear, I can access /index.html successfully, and I'd like to route / to be the same static file, but without redirecting. Any idea how to do this? 回答1: Probably a better answer will eventually come, until then this is my shot at it. If this is not what you want: get '/' do

sinatra helper in external file

左心房为你撑大大i 提交于 2020-01-01 02:28:07
问题 I have lot of helpers in my main Sinatra project_name.rb and I want to remove them to the external file, what is the best practice to do that ? from ./preject_name.rb helpers do ...#bunch of helpers end to for exapmple ./helpers/something.rb thank you 回答1: Just as you said it yourself: Move the helpers block into another file and require it where you need. #helpers.rb helpers do ... end #project_name.rb require 'path/to/helpers.rb' 回答2: The simple and recommended way: module ApplicationHelper

Where does RACK log to?

落花浮王杯 提交于 2020-01-01 01:58:08
问题 I am running a sinatra app through RACK. To which file does the activity get logged ? Also how can I set the log file path ? 回答1: It depends. Many developers define their app log file to app/servername.log or just to the current path where the Rack app is loaded. Yes you can change it's path. Usually you get a config.ru file with something like: log = File.new("sinatra.log", "a+") $stdout.reopen(log) $stderr.reopen(log) # optionally to sync logs while the server is running $stderr.sync = true