0

I have set up mercury in my application. It works properly but since I'm still very new to rails I can't set up authentication. This is what I tried after run: rails generate mercury:install:authentication

  • It seems I can use the module in lib directory

    module Mercury
      module Authentication
    
         def can_edit?
           true if :authenticate_admin!  //(from device)
         end
      end
    end
    

And I tried to use this method in the view but it doesn't work. Lib directory should be autoloaded since that row is not commented in config file.

By the way, just adding a before_filter on the update method, I prevent normal users form confirming edited pages. But they can still see the editor itself if they modify the Url manually which is unwanted.

  • I tried to override Mercury Controller but it doesn't even work

Any suggestion?

Barbared
  • 800
  • 1
  • 8
  • 25
  • You need to define "it doesn't work". Are you getting errors, a stack trace, some logic error? – jdl Jun 30 '12 at 16:22
  • I can't prevent users from seeing the editor. So I'm not using the authentication of Mercury properly. – Barbared Jun 30 '12 at 16:32

2 Answers2

5

Late answer I know but if it helps anyone else.

lib/mercury/authentication.rb

module Mercury
  module Authentication

    def can_edit?
      if user_signed_in? && current_user.admin?
        true
      else 
        redirect_to root_path
      end
   end

 end
end

applicationcontroller.rb

class ApplicationController < ActionController::Base
   protect_from_forgery
   include Mercury::Authentication
 ....

restart your server and then only the admin can see and update the page

Fergal
  • 51
  • 1
  • 2
2

I had the same problem. The solution that worked for me was to explicitly include whichever module handles into authentication.rb like so:

module Mercury
    module Authentication
        include YourAppName::YourAuthenticationModule
        def can_edit?
            admin_signed_in?
        end
    end
end

Insert your module and authentication method accordingly and restart the server

C Blanchard
  • 1,063
  • 9
  • 10