Skip to content

Instantly share code, notes, and snippets.

@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]
@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 / 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 / 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