This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resources :contracts do | |
| get :reprint, on: :member | |
| # or alternatively | |
| member do | |
| get :reprint | |
| end | |
| end | |
| # will generate links like /contracts/123/reprint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= form_for [@page, @page.notes.new] do |f| %> | |
| <%= f.text_area :body %> | |
| <%= f.submit %> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Parameters: {"title"=>"This should do it", "sub_categorisations_attributes"=>[{"sub_category_id"=>3}, {"sub_category_id"=>4}], "product"=>{"title"=>"This should do it"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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 |