Vicki Cijwani's comment is correct, you should give a lot more information (note!), But here is the answer.
You can do this in several ways. If we assume that your authentication method is called protected! :
class MyApp < Sinatra::Base # assumed for all examples get "/only-this-page-has-auth" do protected! "Only admin allowed!" end get "/this-wont-have-auth" do "Everybody can access this" end end
Or you can use a filter
before "/only-this-page-has-auth" do protected! end get "/only-this-page-has-auth" do "Only admin allowed!" end get "/this-wont-have-auth" do "Everybody can access this" end
Or, if you are going to use Sinatra::Namespace from the sinatra-contrib gem (maybe a little more from advanced use, but I use it a lot, because I think this is a good way to do something), and the protected page will now be in folder "/ admin / only-this-page-has-auth"
namespace "/admin" do before do protected! end get "/only-this-page-has-auth" do "Only admin allowed!" end end get "/this-wont-have-auth" do "Everybody can access this" end
source share