Posts

Showing posts from June, 2015

sidekiq css not working in production mode in ruby on rails

Put this in config.ru :-  require 'sidekiq/web' run Rack::URLMap.new(     "/" => Rails.application,     "/sidekiq" => Sidekiq::Web )

List online users with devise in rails

I just add a last_sign_out_at column to my Users table and then subclassed the Devise sessions controller so I could override the destroy method to set it when the session is destroyed (user signs out): # app/controllers class SessionsController < Devise :: SessionsController def destroy current_user . update_attribute (: last_sign_out_at , Time . now ) super end end     And then in my User model I have a method to check if the user is online:   class User < ActiveRecord :: Base def online ? if current_sign_in_at . present ? last_sign_out_at . present ? ? current_sign_in_at > last_sign_out_at : true else false end end end   Also you need to tell Devise to use the new Sessions controller in your routes.  

redirect on multiple sub domain with apache server

 RewriteEngine On RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R]

Whenever cron jobs not working

I added this path in the beginning of schedule.rb:- env :PATH, '/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games'

Add flash message in rails

In app/helpers/application_helper.rb :- module ApplicationHelper     def flash_class(level)         case level         when 'notice' then "alert alert-info"         when 'success' then "alert alert-success"         when 'error' then "alert alert-error"         when 'alert' then "alert alert-error"         end       end end   Somewhere in app/views/layouts/application.html.erb : <%= render 'layouts/flash_messages' %>   app/views/layouts/_flash_messages.html.erb < div > <% flash . each do | key , value | %> < div class = "<%= flash_class(key) %> fade in" > < a href = "#" data - dismiss = "alert" class = "close" >×</ a > <%= value %> </ div > <% end %> </ div > <style> .alert { padding: 8px 35px 8px 14px; margin-bottom: 18px; color: #c09853