Skip to content

Instantly share code, notes, and snippets.

class TaskPolicy < Struct.new(:user, :task)
class Scope < Struct.new(:user, :scope)
def resolve
if user.admin?
scope.all
else
#scope.workpackage.projec
end
end
end
@svisamsetty
svisamsetty / mygov.nic.in_signup.log
Created August 19, 2014 12:39
Request log when loggin into mygov.nic.in
Remote Address:164.100.83.4:80
Request URL:http://www.mygov.nic.in/signup
Request Method:GET
Status Code:404 Not Found
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
@svisamsetty
svisamsetty / gist:7354562
Created November 7, 2013 13:28
how to create a user and add role.
#to create user
@user = User.new
@user.email = 'xyz@gmail.com'
@user.password = 'test123'
@user.save
#to set admin role
@user.add_role :admin
@svisamsetty
svisamsetty / example_controller.rb
Last active December 27, 2015 18:29
Every action which we define in the controller should support and return response in JSON format unless otherwise noted. Below is the gist of how it should look.
#prototype of how an action which returns JSON should look.
def action
@result = Hash.new
@result['status'] = true
@result['error_messages'] = [ ]
@result['success_messages'] = [ ]
if <success>
@clients = Client.all
@clients_data = []
@svisamsetty
svisamsetty / orders_controller.rb
Created November 8, 2013 12:04
Example of how an action which returns JSON response should look like in Rails.
def additemtoorder
@result = Hash.new
@result['status'] = true
@result['error_messages'] = []
@result['success_messages'] = []
@order = Order.find(params[:id])
@product = Product.find(params[:productid])
@skus = ProductSku.where(:product_id=>@product.id).where(:purpose=>'primary')
@svisamsetty
svisamsetty / users_admin_controller.rb
Created November 9, 2013 05:02
Example of add user
def add_user
@result = Hash.new
@result['status'] = true
@result['error_messages'] = [ ]
@result['success_messages'] = [ ]
if params[:password] == params[:password_confirmation]
@user = User.new
@user.fist_name = params[:first_name]
@user.last_name = params[:last_name]
if params[:change_password]
if params[:password].nil? && !params[:password_confirmation].nil? && params[:password] == params[:password_confirmation]
@user.password = params[:password]
end
end
@user = User.new
@user.user_name = params[:user_name]
@user.first_name = params[:first_name]
@user.last_name = params[:last_name]
@user.email = params[:email]
@user.password = params[:password]
@user.password_confirmation = params[:password_confirmation]
@client.user = @user
$http.get('/users_admin/list_users.json').success(function(data) {
if(data.status == true) {
$scope.users_list = data.users;
}
else {
$scope.error_messages = data.error_messages;
// add flag to show error messages in the view.
}
}
{"example":"this is test"}