Skip to content

Instantly share code, notes, and snippets.

View kunalchaudhari's full-sized avatar

Kunal kunalchaudhari

View GitHub Profile
@kunalchaudhari
kunalchaudhari / rails http status codes
Created July 2, 2017 07:58 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@kunalchaudhari
kunalchaudhari / application_controller.rb
Last active October 14, 2015 17:15
Token based auth
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
# before_action :detect_device_variant
before_action :authenticate_user!
before_action :set_location
rescue_from CanCan::AccessDenied do |exception|
if current_user && !current_user.admin?
redirect_to main_app.root_path
@kunalchaudhari
kunalchaudhari / application_controller.rb
Created July 30, 2012 09:35
forem: allow anonymous user to create post/topic
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
layout "general"
helper_method :forem_user
def forem_user
current_user || anonymous_user
end
@kunalchaudhari
kunalchaudhari / _form.html.erb
Created July 11, 2012 14:52
i am using forem gem and i have post model decorator. i would like to make the post taggable and using the act-as-taggable-on gem. but it giving me error that tag_list method is undefine. when i do post = Forem.Post.new and post.tag_list = 'tag1 tag2' in
<%= f.input :text %>
<%= f.input :tag_list %>
<% if params[:reply_to_id] %>
<%= f.hidden_field :reply_to_id, :value => params[:reply_to_id] %>
<% end %>
@kunalchaudhari
kunalchaudhari / 1 of 3 - application.js
Created March 15, 2012 04:05
Simplify Spree's checkout login
// Simplify Spree's checkout login: http://i.imgur.com/aXE4V.png
//
// App available at https://github.com/mikkelb/tootie
//
// If the user has a password, log in and proceed with regular checkout. If she doesn't,
// proceed with guest checkout.
//
// CURRENT STATUS: Only regular checkouts work - it doesn't know how to do guest checkouts.
//
// <iszak> I don't understand why you're even using JS to dictate the path, why not have two