breaking into the unknown…

rails_admin custom logout link

Leave a comment

rails_admin generally work with devise. Its logout link simply destroy the user session. But in my application, although I am using devise, the actual authentication is done on OPENAM. If user is authenticated on OPENAM, I used to sign_in the user with devise. Similarly, the logout link on my application go to my custom action, where I destroy the user session on OPENAM and then call devise sign_out method to destroy the devise user session.

So basically, on rails_admin, I want to change the logout url from “/users/sign_out” which call devise  sessions#destroy action to “/logout“, which will call my custom logout method.

Unfortunately, I do not find any configuration option provided by rails_admin to this. I do find a thread here , which talked of the configuration option introduced for logout, but some how it do not worked for me, may be the changes are not present in current rails_admin 0.4.3.

The workaround, is to replace the link on page load for rails admin. You can add custom js or css to rails_admin. It is explained here .

In our case to change, the rails_admin logout link follow the below steps :

STEP 1: create rails_admin js override file

add ui.js file at below location in your application –

app/assets/javascripts/rails_admin/custom/ui.js # any js code in this file will override, those set in rails_admin

STEP 2 : write the js code to replace the logout link.

      #It will check that the page do contain the link to be replaced
      if($("a[href='/users/sign_out']").length > 0){ 
      $("a[href='/users/sign_out']").attr("href", "/logout")

that’s all, now whenever user click on logout link, it will take him to your custom logout action.

STEP 3: Adding Static links to Rails Admin

Though not related to logout link, I want to mention it that you can add any static link to rails Admin Navigation.

It is explained here .


Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s