0

I am using rails 4 and comfortable mexican sofa. I wish to secure some cms pages with password protection. They don't need to be very secure. The following code gives me an undefined method error:

module CmsPagesAuth

  def authenticate
    http_basic_authenticate_with name: "dhh", password: "secret"
  end
end

the method is part of ActionController::HttpAuthentication::Basic How to I get access to the method in question? Or is there a better way I should be going about this problem? Thanks in advance for any suggestions, solutions or insights.

laertiades
  • 1,992
  • 2
  • 19
  • 26
  • you would have to do this in your controller – usha Oct 24 '13 at 21:47
  • application_controller.rb? – laertiades Oct 24 '13 at 21:52
  • yes if you want it to be applied for all the controllers. If not, add it to the specific controller – usha Oct 24 '13 at 21:53
  • 1
    I see you read the wiki entry about this. Cool. But I think you want to use `authenticate_or_request_with_http_basic` method http://apidock.com/rails/ActionController/HttpAuthentication/Basic/ControllerMethods/authenticate_or_request_with_http_basic It's basically implementation of the default auth cms is using: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/authentication/http_auth.rb If you want to protect only certain pages just check for `@cms_path.full_path` before doing that basic auth. – Grocery Oct 24 '13 at 22:56
  • @Grocery, thank you. Your suggestion worked and I am on the right track. My implementation of your suggestion seems to conflict with CMS admin Auth so I may have to use some other form of Auth anyways but your suggestion cleared some things up. Thank you. – laertiades Oct 25 '13 at 14:36

1 Answers1

0
class StaticController < ApplicationController
   http_basic_authenticate_with name: "dhh", password: "secret", only: [your static actions]
end
usha
  • 28,973
  • 5
  • 72
  • 93
  • thank you vimsha. That worked. However, all my cms pages seem to be controlled by: CmsContentController#render_html so I am not sure how to exclude certain pages. If I am not mistaken, CMS seems to de-emphasize the use of Controllers. – laertiades Oct 24 '13 at 22:12