rack

Making Rails tests aware of Rack middleware outside Rails's internal chain

白昼怎懂夜的黑 提交于 2019-12-03 07:08:16
问题 Context : an application uses a piece of Rack middleware that must be setup in config.ru, rather than Rails's internal Middleware chain. This is for reasons not relevant to this question. Question : how do I make my tests (functional and integration) aware of this middleware? I'll ellaborate with an example. Let's create a pristine Rails 3 app, using rack-rewrite for illustration purposes. # /config/initializers/example.rb Rails.application.middleware.insert 0, 'Rack::Rewrite' do r301 '/so',

Static website on Heroku Cedar

荒凉一梦 提交于 2019-12-03 06:56:46
I tried following the instructions here in order to create a static website on Heroku's Cedar stack. I have put the site up here . When I try to push the app (using "git push heroku master"), I get the following error: Kushs-MacBook-Air:hgtr kushpatel$ git push heroku master Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (7/7), 1.29 KiB, done. Total 7 (delta 1), reused 0 (delta 0) -----> Heroku receiving push -----> Removing .DS_Store files ! Heroku push rejected, no Cedar-supported app detected To git@heroku.com

Where does RACK log to?

為{幸葍}努か 提交于 2019-12-03 05:27:55
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 ? include 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 $stdout.sync = true and/or configure do LOGGER = Logger.new("sinatra.log") enable :logging, :dump

Redirect logger output for a specific controller in Rails 4

坚强是说给别人听的谎言 提交于 2019-12-03 05:11:30
I've built a solution based on the answer in my previous question Redirect logger output for a specific controller in Rails 3 for Rails 3. It works great however now I am trying to apply the same middleware based solution to a Rails 4 project but there are some differences keeping the same solution from working. The Rails 3 solution: module MyApp class LoggerMiddleware REPORTS_API_CONTROLLER_PATH = %r|\A/api/v.*/reports.*| REPORTS_API_CONTROLLER_LOGFILE = "reports_controller.log" def initialize(app) @app = app @logger = Rails::logger .instance_variable_get(:@logger) .instance_variable_get(:

You have already activated rack 1.3.2, but your Gemfile requires rack 1.2.3. Consider using bundle exec

旧时模样 提交于 2019-12-03 04:17:00
I've got a problem while i try to run my app : You have already activated rack 1.3.2, but your Gemfile requires rack 1.2.3. Consider using bundle exec. I read a lot about this kind of error, but i did not find any solution that worked for me I already removed my Gemfile.lock and re-run bundle as suggested here I already use the latest version of passenger (3.0.8) - as suggested here The bundle exec rake trick cannot be used in my case Thank you per advance Run bundle install --binstubs and you'll get bin directory in your application root with all executables needed by app. Then you need to

How do I set a cookie with a (ruby) rack middleware component?

时光怂恿深爱的人放手 提交于 2019-12-03 02:54:05
I'm writing a rack middleware component for a rails app that will need to conditionally set cookies. I am currently trying to figure out to set cookies. From googling around it seems like this should work: class RackApp def initialize(app) @app = app end def call(env) @status, @headers, @response = @app.call(env) @response.set_cookie("foo", {:value => "bar", :path => "/", :expires => Time.now+24*60*60}) [@status, @headers, @response] end end which doesn't give errors, but doesn't set a cookie either. What am I doing wrong? If you want to use the Response class, you need to instantiate it from

Deleting the current session with Rack::Session::Cookie

与世无争的帅哥 提交于 2019-12-03 01:14:20
I feel like I'm missing something obvious here, and I'm hoping that as soon as I post this someone will shame me with the google search link I was missing :-) enable :sessions get '/logout' do # What goes here to kill the session? end Jonas Fagundes Just use session.clear to destroy the session. It depends how you create your session. Simply you have to nulify session entry. Here is simple example, how to create and destroy sessions. get '/login' do session[:username] = params[:username] "logged in as #{session[:username]}" end get '/logout' do old_user = session[:username] session[:username]

Sinatra, JavaScript Cross-Domain Requests JSON

折月煮酒 提交于 2019-12-03 00:51:48
I run a REST-API build on top of Sinatra. Now I want to write a jQuery Script that fetches data from the API. Sinatra is told to response with JSON before do content_type :json end A simple Route looks like get '/posts' do Post.find.to_json end My jQuery script is a simple ajax-call $.ajax({ type: 'get', url: 'http://api.com/posts', dataType: 'json', success: function(data) { // do something } }) Actually everything works fine as long as both runs on the same IP, API and requesting JS. I already tried to play around with JSONP for Rack without any positive results, though. Probably I just need

faye ruby client is not working

冷暖自知 提交于 2019-12-03 00:42:59
I am using faye on my Rails 2.1 app. And after testing and fixing many things faye ruby client is not working. This is my server code. require 'faye' server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45) EM.run { thin = Rack::Handler.get('thin') thin.run(server, :Port => 9292) server.bind(:subscribe) do |client_id, channel| puts "[ SUBSCRIBE] #{client_id} -> #{channel}" end server.bind(:unsubscribe) do |client_id, channel| puts "[UNSUBSCRIBE] #{client_id} -> #{channel}" end server.bind(:disconnect) do |client_id| puts "[ DISCONNECT] #{client_id}" end } This is my client side JS

Where to insert Rack::Deflater in the rack?

我们两清 提交于 2019-12-03 00:37:23
I currently have the following: use Rack::Rewrite use Rack::Cache, {:verbose=>true, :metastore=>"memcached://localhost:11211/rack-cache/meta", :entitystore=>"memcached://localhost:11211/rack-cache/body"} use Rack::Rewrite use Rack::Lock use Rack::Deflater use ActionController::Failsafe use #<Class:0x007fb34be9ac90> use ActionController::Session::DalliStore, #<Proc:0x007fb34bea3638@(eval):8 (lambda)> use Rails::Rack::Metal use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActionController::StringCoercion use Sass::Plugin::Rack use Hassle use ActiveRecord: