Skip to content

Instantly share code, notes, and snippets.

View jasdeepsingh's full-sized avatar
🏠
Working from home

jasdeep singh jasdeepsingh

🏠
Working from home
View GitHub Profile
@jasdeepsingh
jasdeepsingh / gist:1274617
Created October 10, 2011 04:11
Installing/Building ImageMagick and Rmagick Gem on Mac OS X Lion
cd ~/src
git clone git://github.com/masterkain/ImageMagick-sl.git
cd ImageMagick-sl
sh install_im.sh
sudo gem install rmagick
@jasdeepsingh
jasdeepsingh / aws-s3.rb
Created October 10, 2011 05:04
/config/initializers/s3.rb:1:in `<top (required)>': uninitialized constant AWS (NameError) - AWS-S3 Gem not working Mac OS X Lion
# If you are facing such an Error while installing/working with the aws-s3 gem
# /config/initializers/s3.rb:1:in `<top (required)>': uninitialized constant AWS (NameError)
# try adding this to your Gemfile instead..
gem 'aws-s3', :require => 'aws/s3'
# I was having this issue on Mac OS X Lion with aws-s3 gem 0.6.2
@jasdeepsingh
jasdeepsingh / Gemfile
Created October 10, 2011 18:44 — forked from ecpplus/Gemfile
[Rails] fix `autodetect': Could not find a JavaScript runtime. error
gem 'therubyracer' # add this
@jasdeepsingh
jasdeepsingh / users_controller.rb
Created November 3, 2011 00:01
User Controller
class UsersController < ApplicationController
def create
@user = User.new(params[:user])
@fbUser = session[:fbUser]
if @user.save
flash[:notice] = "Success"
#redirect_to :action => "success"
redirect_to :root
else
flash[:error] = "The below errors prevented your request from being processed:"
@jasdeepsingh
jasdeepsingh / api_controller.rb
Created November 3, 2011 00:03
API Controller
class ApiController < ApplicationController
before_filter :authenticate_user!
skip_before_filter :verify_authenticity_token
def store_coordinates
@store = Geocoder.search(params[:address])
render :json => @store[0].geometry
end
@jasdeepsingh
jasdeepsingh / sessions_controller.rb
Created November 3, 2011 00:03
Sessions Controller
class SessionsController < Devise::SessionsController
skip_before_filter :verify_authenticity_token
def create
#resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
resource = warden.authenticate!(:scope => resource_name, :recall => "sessions#failure" )
if !resource.blank?
flash[:notice] = "Signed in successfully!"
end
@jasdeepsingh
jasdeepsingh / stores_controller.rb
Created November 3, 2011 00:04
Stores Controller
class StoresController < ApplicationController
before_filter :authenticate_user!
def index
@user = current_user
@stores = current_user.stores
end
def new
@user = current_user
@store = current_user.stores.build
@jasdeepsingh
jasdeepsingh / ability.rb
Created November 3, 2011 00:05
Ability Model
# The below file was used in a project that required the use of CanCan Gem
# Author: Jasdeep Narang
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.role? :admin
@jasdeepsingh
jasdeepsingh / deal.rb
Created November 3, 2011 00:07
Deal Model
class Deal < ActiveRecord::Base
# Associations
has_and_belongs_to_many :stores
belongs_to :user, :class_name => "User", :foreign_key => "merchant_id"
has_many :punches
# To-do: Validations
# Add validations on the deals model
@jasdeepsingh
jasdeepsingh / store.rb
Created November 3, 2011 00:07
Store Model
class Store < ActiveRecord::Base
# Associations
belongs_to :user, :class_name => "User", :foreign_key => "merchant_id"
has_and_belongs_to_many :deals
# Validations
validates_presence_of :name, :street_address, :city, :postal_code, :province, :country_field
geocoded_by :address
after_validation :geocode