Where to put conditions that are needed in extensions and main app

9 views
Skip to first unread message

Iain Barnett

unread,
Jan 29, 2012, 2:08:09 PM1/29/12
to sina...@googlegroups.com
Hi all,

I've written a condition to enforce ssl on some pages, but during development it's set to off:

    register do

      def ssl_only( _ )
        condition do
          if settings.ssl_on
            redirect File.join("https://", request.host, request.path_info ), 301 unless request.host.start_with? 'localhost'
          end
        end
      end

    end

Then I can use:

    configure :development do
      set :ssl_on, false
    end # ...

    get "/login/?", :ssl_only => true do
      #...

but, I've an extension with routes defined that should also use this condition. If I go ahead and add it to the extension's routes, the following error message appears:

    undefined method `ssl_only' for Sinatra::Application:Class (NoMethodError)


The ssl_only method is registered in the main (modular style) app before the extension is required and registered.


I'm wondering if I need to perhaps move the ssl_only condition out into its own extension that is then registered within the main app and in the current extension? Or is there some other way to stop the no method error?

Any insight or help will be much appreciated.

Regards,
Iain
Reply all
Reply to author
Forward
0 new messages