FAQ Database Discussion Community


Why is Unicorn looking for rackup file (config.ru) even though I am specifying a config?

ruby-on-rails,ruby-on-rails-4,rack,unicorn,rackup
I am simply SSH'd into my Ubuntu 14.04 server instance, trying to bootstrap my Unicorn server for a Rails 4.2 app. cd /home/sh0/app/current/api bundle exec unicorn -E production -c /home/sh0/app/current/api/config/unicorn.rb But it fails! /usr/local/lib/ruby/gems/2.0.0/gems/unicorn-4.9.0/lib/unicorn/configurator.rb:657:in `parse_rackup_file': rackup file (config.ru) not readable (ArgumentError) from /usr/local/lib/ruby/gems/2.0.0/gems/unicorn-4.9.0/lib/unicorn/configurator.rb:77:in `reload' from...

How do I display registration errors in Rack

ruby-on-rails,ruby,rack
I have a simple Rack app, here is the sign up part : class SignUp def call(env) req = Rack::Request.new(env) if req.post? User.register(req.params) [ 301, { 'Location' => '/login' }, [] ] else [ 200, { 'Content-Type' => 'text/html' }, [File.read('signup.html')]] end end end What I want to do is...

Ruby on Rails Rack middleware exclude

ruby-on-rails,rack
I want to configure middleware to exclude certain paths from basic auth. I am able to do this like the following: config.middleware.insert_after(::Rack::Lock, "AuthenticateExcluding", realm: "Staging", exclude: ["/webhooks/stripe", "/api/v2/gadgets"]) do |u, p| However, I would like to exclude a all routes that match a certain pattern such as /api/v2/gadgets/:gadget_id/specs (contrived example)....

How do I prevent my routes.rb from intercepting requests coming to /blog?

ruby-on-rails,ruby-on-rails-4,routing,rack,middleman
My /blog directory is just a bunch of static HTML files. That's good. When I go to localhost/blog it works fine - it renders the index.html for my middleman generated blog. Great. But when I click on any of the posts, it gives me a routing error: No route matches...

Static File serving using Rack

ruby,rack,cuba
I have this block of code: require "cuba" require "mote" require "mote/render" Cuba.plugin(Mote::Render) Cuba.use Rack::Static, # urls: %w[/index], root: File.expand_path("./public", __dir__) Cuba.define do on(root) do render("index", title: "Welcome") end end and I'm trying to server the file in the public folder(which is in the same directory as the this file...

Rewrite Rails response URL

ruby-on-rails,rack,actioncontroller
I saw this. I did params.select!{|k, v| v.present?} which cleans blank params, but I do not know how to make the response URL to be cleaned. I continue getting something like http://localhost:3000/restaurants/search?utf8=%E2%9C%93&city=&cuisine=&number_of_people=&query=hello I am looking for http://localhost:3000/restaurants/search?utf8=%E2%9C%93&query=hello Also, I would delete utf8 param, is that bad? Update I am considering...

Heroku PostgreSQL database connection pooling in Ruby for Rack with Puma

ruby,postgresql,heroku,connection-pooling,rack
UPDATE: I tried changing the storage of the PostgreSQL connection object from a constant POSTGRES to a class variable @@pg. That didn't fix the issue. Then, I tried changing it to a global variable $pg. That seems to have worked! I still would like to eventually implement database connection pooling,...

How to work with rack using ruby for storing image on cloudinary with gem carrierwave

ruby,rack,grape
I am using rack framework with active record and there is no rails , so when i upload an image to cloudinary using carrierwave gem i am getting the following error. Unexpected error while processing request: uninitialized constant Cloudinary::CarrierWave::Storage::Rails ...

How to write portable image paths in CSS files for a mounted sinatra app?

sinatra,rack
Background You are writing a sinatra (or rack) application, and want to be able to use it, with no code changes, both as a standalone app, or as a mounted app. That is, you might run this application on its own, or you might mount it as a sub-application inside...

JSON parameters not available in request hash (Rails, omniauth-google-oauth2 gem)

ruby-on-rails,json,omniauth,rack
Overview I want to implement the Google OAuth2 server side (hybrid) with the Omniauth Google OAuth2 Gem (0.2.6). However, the code parameter I send to my app does not get added to the request.params hash. Thus, OmniAuth throws an error, as it can't find the code. Details After retrieving the...

Should I instantiate an object every request or once upon app launch?

ruby,amazon-web-services,amazon-s3,rack,aws-sdk
In my Rack app, I need to use an AWS Cognito Client for signup & login requests. Should I initialize: a separate client (assigned to a local variable inside the call method) for each request? one client (assigned to a global variable outside the call method) for all requests? Concerns:...

What is Rack::Utils.multipart_part_limit within Rails and what function does it perform?

ruby-on-rails,ruby,rack,multipart
Rack::Utils.multipart_part_limit is set to 128 by default. What purpose does the value have and what effect does it have within the Rails system?...

Using rack-cors with Rackspace CDN issues

ruby-on-rails,cors,rack,font-awesome,rackspace
I have a rails 4.2 app using rack-cors. None of my font-awesome icons show up even though all my other assets are fine. I'm using the rackspace cdn. My CDN url looks something like http://ddf908e003b5678bc25-9d6bfcdc12345678ba868a15bca98.r12.cf5.rackcdn.com/assets/main-4f3595479ce96112e1b8ab4e5357fc26.css My rack-cors config is in my config/application.rb config.middleware.insert_before 0, "Rack::Cors" do allow do origins 'localhost:3000',...

Heroku HTML static site does not allow json access?

heroku,rack
I'm using Rack::TryStatic to manage my site on Heroku. This is my config.ru file on github require "rack/contrib/try_static" require "rack/contrib/not_found" use Rack::TryStatic, { root: "_site", urls: %w[/], try: %w[ .html index.html /index.html .js .css .xml .json .eot .svg .ttf .woff .woff2 ] } run lambda{ |env| four_oh_four_page = File.expand_path("../_site/404/index.html", __FILE__)...

Rendering an “internal” Rails controller from a middleware

ruby-on-rails,rack,middleware,actionpack
I have a Rails middleware stack, and I have a piece of MW outside ActionDispatch. Ideally I would like to render a page using ActionDispatch by triggering a URL which is internal (not accessible via usual URL routes) - similar to the way Devise renders it's "auth failed" pages. The...