Skip to content

Instantly share code, notes, and snippets.

View TechFounder's full-sized avatar

Jimmy Chen TechFounder

View GitHub Profile
@TechFounder
TechFounder / registrations_controller.rb
Last active December 27, 2015 04:29
If you need to make sure that only one Devise user class is logged in and that users can't register as another class if they are already logged in, you need to pre-check their status. To do that use these following snippets.
# Create this new controller for registrations to check that they're not already registered
class RegistrationsController < Devise::RegistrationsController
def new
if (user_signed_in? || admin_signed_in?)
redirect_to '/', alert: "You cannot register two roles at the same time!"
else
super
end
@TechFounder
TechFounder / _header.html.erb
Last active December 24, 2015 09:39
This is code so that the nav bar will show the correct corresponding user page where the devise gem is used to create 3 separate user classes: User, Admin, Company User. I think there are instances where developers who choose not to go down the STI route. There are 2 parts to the code. First a header partial where the conditions are set for the …
<ul class="left">
<% if user_signed_in? %>
<li><%= link_to "Home Page", root_path %></li>
<% elsif admin_signed_in? %>
<li><%= link_to "Home Page", root_path %></li>
<li><%= link_to "Admin Home Page", admin_path %></li>
<% elsif company_user_signed_in? %>
<li><%= link_to "Home Page", root_path %></li>
<li><%= link_to "Company Home Page", company_path %></li>
<% else %>
#!/usr/bin/ruby
#
# This script fixes /usr/local only.
#
# 6th January 2010:
# Modified the script to just fix, rather than install. - rpavlik
#
# 30th March 2010:
# Added a check to make sure user is in the staff group. This was a problem
# for me, and I think it was due to me migrating my account over several
img {
cursor:pointer;
}
#fade {
width: 100px;
height: 100px;
border-radius: 50%;
border: none;
}