Skip to content

Instantly share code, notes, and snippets.

View sevenseacat's full-sized avatar
🏠
Working remotely

Rebecca Le sevenseacat

🏠
Working remotely
View GitHub Profile
## app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<% if current_user.admin? %>
<%= stylesheet_link_tag 'application_admin' %>
<% else %>
<%= stylesheet_link_tag 'application_nonadmin' %>
<% end %>
resources :contracts do
get :reprint, on: :member
# or alternatively
member do
get :reprint
end
end
# will generate links like /contracts/123/reprint
Recovering stashes that were cleared/dropped erroneously
If you mistakenly drop or clear stashes, they cannot be recovered through the normal safety mechanisms. However, you can try the
following incantation to get a list of stashes that are still in your repository, but not reachable any more:
git fsck --unreachable |
grep commit | cut -d\ -f3 |
xargs git log --merges --no-walk --grep=WIP
class PostsController < ApplicationController
before_filter :authenticate_user, except: [:index, :show]
def authenticate_user
# I presume you have a current_user helper defined on your controller to get the authenticated user?
raise ActionController::RoutingError, 'No valid user' unless current_user.present?
end
end
<%= form_for [@page, @page.notes.new] do |f| %>
<%= f.text_area :body %>
<%= f.submit %>
<% end %>
@sevenseacat
sevenseacat / bad
Created May 7, 2014 06:41 — forked from anonymous/log
Parameters: {"title"=>"This should do it", "sub_categorisations_attributes"=>[{"sub_category_id"=>3}, {"sub_category_id"=>4}], "product"=>{"title"=>"This should do it"}}
@sevenseacat
sevenseacat / user.rb
Last active December 28, 2015 06:58
Alternatives for a full_name method
class User
# Downsides - when first name is nil, you'll have a string like " LastName"
def full_name
"#{first_name} #{last_name}"
end
# Downsides - a bit harder to understand
def full_name
[first_name, last_name].compact.join(' ')
end
Started GET "/" for 127.0.0.1 at 2013-11-05 10:20:01 +0800
ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PagesController#home as HTML
JobSpecialty Load (1.3ms) SELECT "job_specialties".* FROM "job_specialties"
Rendered application/_region_select.html.haml (1.9ms)
Rendered application/_job_search.html.haml (1558.8ms)
Rendered application/_banner.html.haml (1563.6ms)
Cache digest for pages/home.html: 2582a0d4c5e51f7cf18c551cceb4eb3c
Read fragment views/home/2582a0d4c5e51f7cf18c551cceb4eb3c (0.2ms)
Write fragment views/home/2582a0d4c5e51f7cf18c551cceb4eb3c (1.3ms)
class ApplicationController < ActionController::Base
# Overwrite Devise's authenticate_user! to store where they should be redirected back to
def authenticate_user!(opts={})
session[:user_return_to] = request.referrer
super(opts)
end
# Change redirect after Devise login; defaults to root_url
def after_sign_in_path_for(user)
stored_location_for(user) || dashboard_path
@sevenseacat
sevenseacat / gist:7096266
Created October 22, 2013 06:57
cool story activeadmin
$ gem install activeadmin
ERROR: While executing gem ... (Gem::ImpossibleDependenciesError)
arbre-1.0.1 requires activesupport (>= 3.0.0) but it conflicted:
Activated activesupport-4.0.0 instead of (= 3.2.15) via:
activerecord-3.2.15, meta_search-1.1.3, activeadmin-0.6.2
Activated activesupport-3.2.15 instead of (= 4.0.0) via:
railties-4.0.0, devise-3.1.0, activeadmin-0.6.2