Skip to content

Instantly share code, notes, and snippets.

View goodviber's full-sized avatar

GoodViber goodviber

View GitHub Profile
@goodviber
goodviber / SEO urls for shopping cart in rails
Last active August 29, 2015 14:25
Rails 4 URL setup to find model instances (eg products) by numerical id for puposes of cart addition and find by slug for purposes of SEO display. Will display in browser as app/products/my-url-goes-here, but will send params as "product_id" => 1. Completely Bonzer!
# PRODUCT MODEL
before_create do
self.slug = title.downcase.gsub(" ", "-")
end
def to_param
[id, title.parameterize].join("-")
end
@goodviber
goodviber / admin products
Created June 12, 2015 20:59
Scaffold generated Rspec for nested controller
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
bundle exec rake db:drop RAILS_ENV=test # if db already exists
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test
GOOGLE SETTINGS
https://accounts.google.com/DisplayUnlockCaptcha
https://www.google.com/settings/security/lesssecureapps
@site_audits = @site_audits.joins(audit_specification: :service_category).where(service_categories: { id: params[:service][:category] })
tail -f /var/log/nginx/error.log
@goodviber
goodviber / rails boolean
Created November 22, 2016 12:44
3 state boolean
add_column :users, :admin, :boolean, null: false, default: false
brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
list = @job.job_status #array
list.shift
@job.job_status = list
@job.job_status_will_change!
@job.save!
bundle exec rake stock_update RAILS_ENV=production
rails console production