2

In my app as part of my settings I

set :public, Proc.new { File.join(root, 'public') }

but if I look at the variable public in my config blocks, it's an Object that represents the whole app (or seems to)

public.to_json -->

{"extensions":[],"conditions":[],"routes":{},
 "inheritable_attributes":{},"errors":{},"prototype":null,"active_user":null,
 "templates":{},"filters":{"after":[],"before":[]},
 "middleware":[],"models_are_loaded":true}

but in my config block public used to just resolve to 'public'

this is bugging me because each request to my app now complains that it "can't convert Class into String" for the line

set :images, Proc.new {File.join(public, 'images')}

but weirdly this used to work fine

Has something changed in Ruby or Sinatra in the last three weeks (I've been on holiday and this worked before I left)?

Note I've also tried just leaving the set :public, ... bit commented out as I used to do but that gives the same result.

1 Answer 1

4

As of sinatra 1.3, public has been deprecated in favor of public_folder. This was done to avoid overloading Module#public

It's now:

dir = File.dirname(__FILE__)
set :public_folder, "#{dir}/public"

I'm not sure why you are using a Proc though in your examples...

2
  • thanks. I just used Proc as that's how the various docs said to do it, and back then I knew very little Ruby. And until now it's worked fine so thought to change it. But yes I see I could optimise this app in a number of ways :-)
    – Dave Sag
    Nov 9, 2011 at 5:43
  • Yeah I imagine the Proc worked on older versions due how the settings were read. My guess is they've changed the settings handle code.
    – mjc
    Nov 9, 2011 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.