Skip to content

Instantly share code, notes, and snippets.

result_budget_item = Hash.new
result_budget_item['budget_item'] = budget_item
result_budget_item['approved_to_date'] = budget_item.get_approved_amount
result_budget_item['claim_to_date'] = budget_item.get_claimed_amount
@result_item_hash['budget_items'] << budget_item
{"error_messages":[],"success_messages":["Action performed successfully"],"status":true,
"data":[{"client_info":
{"company_name":"Client Pty Ltd","created_at":"2013-11-23T07:43:19Z","id":1,
"updated_at":"2013-11-23T07:43:19Z","user_id":null},
"client_project_info":
[{"basic_info": {"client_id":1,
"created_at":"2013-11-23T07:45:53Z",
"description":"Test Project For Client Pty Ltd","id":7,
"name":"Test Project",
$scope.reset_messages = function() {
$scope.error_messages = [];
$scope.success_messages = [];
$scope.show_success_message = false;
$scope.status = null;
}
$scope.reset_messages();
$http.post('url').success(function(data){
$scope.status = data.status;
if (data.status) {
$scope.success_messages = data.success_messages;
}
else {
$scope.error_messages = data.error_messages;
}
}).error(function() {
{"example":"this is test"}
$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.
}
}
@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
if params[:change_password]
if params[:password].nil? && !params[:password_confirmation].nil? && params[:password] == params[:password_confirmation]
@user.password = params[:password]
end
end
@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')