rack

Rails/Rack: “ArgumentError: invalid %-encoding” for POST data

不打扰是莪最后的温柔 提交于 2019-11-30 16:52:52
问题 Our ruby on rails site has a URI that one of our partners POSTs XML data to. Since we don't want to deal with XML, we literally just stuff the raw data into a database column and don't go any further with processing it. However, one of the posts we received gave us this error in airbrake: ArgumentError: invalid %-encoding ("http://ns.hr-xml.org/2004-08-02" userId="" password=""><BackgroundReportPackage type="report"> <ProviderReferenceId>.... With backtrace: vendor/ruby-1.9.3/lib/ruby/1.9.1

How to receive a JSON object with Rack

…衆ロ難τιáo~ 提交于 2019-11-30 15:45:59
问题 I have a very simple Ruby Rack server, like: app = Proc.new do |env| req = Rack::Request.new(env).params p req.inspect [200, { 'Content-Type' => 'text/plain' }, ['Some body']] end Rack::Handler::Thin.run(app, :Port => 4001, :threaded => true) Whenever I send a POST HTTP request to the server with an JSON object: { "session": { "accountId": String, "callId": String, "from": Object, "headers": Object, "id": String, "initialText": String, "parameters": Object, "timestamp": String, "to": Object,

How to receive a JSON object with Rack

十年热恋 提交于 2019-11-30 15:07:07
I have a very simple Ruby Rack server, like: app = Proc.new do |env| req = Rack::Request.new(env).params p req.inspect [200, { 'Content-Type' => 'text/plain' }, ['Some body']] end Rack::Handler::Thin.run(app, :Port => 4001, :threaded => true) Whenever I send a POST HTTP request to the server with an JSON object: { "session": { "accountId": String, "callId": String, "from": Object, "headers": Object, "id": String, "initialText": String, "parameters": Object, "timestamp": String, "to": Object, "userType": String } } I receive nothing. I can detect the request received but can't get the data. The

Specifying Content Type in rspec

自闭症网瘾萝莉.ら 提交于 2019-11-30 14:36:36
问题 I'm trying to build an rspec test that sends JSON (or XML) via POST. However, I can't seem to actually get it working: json = {.... data ....}.to_json post '/model1.json',json,{'CONTENT_TYPE'=>'application/json'} and this json = {.... data ....}.to_json post '/model1.json',json,{'Content-Type'=>'application/json'} any ideas? THANKS! 回答1: There's a way to do this described in this thread -- it's a hack, but it seems to work: @request.env["HTTP_ACCEPT"] = "application/json" json = { ... data ..

Is it possible include Nesta CMS into Rails3 application?

坚强是说给别人听的谎言 提交于 2019-11-30 14:19:09
问题 I'd like "to mount" a Nesta CMS app onto a Rails3 app This should be possible couse of being Nesta a Sinatra app, which should be a Rack mountable layer, ... but how would you do it ? Where will you start from ? Does anybody has experiences on this topic ? Suggested docs ? 回答1: Hey Luca. I've been meaning to write this up a for a month or two. You just need to mount Nesta as a Rack app, using Rails Metal. Have a watch of this: http://railscasts.com/episodes/222-rack-in-rails-3 You'll be able

Is there any debug toolbar for Rails 3.x

谁都会走 提交于 2019-11-30 14:02:09
问题 I used Rack::Bug more than one year ago, now I'd like to use it with a new Rails 3.1 project. I tried to install it, both the master and rails3 branches, but with no luck. Also tried some github forks but they did not work either. Is there any alternative with the same features? P.S. I already know newrelic and its developer mode, just looking for something else, more similar to Rack::Bug Here is a little screen shoot of what is capable of (the green toolbar with debugging informations) 回答1:

How do I use a Rack middleware only for certain paths?

半世苍凉 提交于 2019-11-30 12:23:44
问题 I'd like to have MyMiddleware run in my Rack app, but only for certain paths. I was hoping to use Rack::Builder or at least Rack::URLMap , but I can't quite figure out how. This is what I thought would work, but doesn't: # in my rackup file or Rails environment.rb: map '/foo' do use MyMiddleware, { :some => 'options' } end Or, better yet, with a Regexp: map /^foo/ do use MyMiddleware, { :some => 'options' } end But map seems to demand an app at the end; it won't fall back on just passing

Any way to serve gzip assets from heroku?

删除回忆录丶 提交于 2019-11-30 11:24:49
问题 I'm wondering if there is any way to get the Rails webserver (thin) to serve the *.gz files the asset pipeline creates. As I understand, those have a higher compression level than that of Rack::Deflater , which only works with serve_static_assets from within the rackup file and not in config.middleware . A less optimal solution might be to change the default compression level of Zlib which is what Rack::Deflater references. It should only need to gzip once, then it goes to Rack::Cache , then

Is it possible include Nesta CMS into Rails3 application?

蓝咒 提交于 2019-11-30 10:38:00
I'd like "to mount" a Nesta CMS app onto a Rails3 app This should be possible couse of being Nesta a Sinatra app, which should be a Rack mountable layer, ... but how would you do it ? Where will you start from ? Does anybody has experiences on this topic ? Suggested docs ? Hey Luca. I've been meaning to write this up a for a month or two. You just need to mount Nesta as a Rack app, using Rails Metal. Have a watch of this: http://railscasts.com/episodes/222-rack-in-rails-3 You'll be able to refer to Nesta in your routes by referring to it as Nesta::App (I only merged the commit that allows you

What's the difference between request.remote_ip and request.ip in Rails?

只谈情不闲聊 提交于 2019-11-30 10:24:13
问题 As the title goes, you can get the client's ip with both methods. I wonder if there is any differences. Thank you. in the source code there goes "/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.3/lib/action _dispatch/http/request.rb" 257L, 8741C def ip @ip ||= super end # Originating IP address, usually set by the RemoteIp middleware. def remote_ip @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s end but I really don't know the implications. 回答1: From source: module