我在一个简单的Rails API中有以下控制器代码:
class Api::V1::AccountsController < ApplicationController
def index
render json: Account.all
end
def show
begin
render json: Account.includes(:cash_flows).find(params[:id]), include: :cash_flows
rescue ActiveRecord::RecordNotFound => e
head :not_found
end
end
end
Run Code Online (Sandbox Code Playgroud)
这个问题是,生成的json具有以下格式:
{
id:2,
name: 'Simple account',
cash_flows: [
{
id: 1,
amount: 34.3,
description: 'simple description'
},
{
id: 2,
amount: 1.12,
description: 'other description'
}
]
}
Run Code Online (Sandbox Code Playgroud)
我需要我生成的json是camelCase('cashFlows'而不是'cash_flows')
提前致谢!!!
我想创建一个类似于此的Elixir代码:
def infinite_loop(created_workers \\ []) do
case next_from_queue do
{:ok, queue_msg} ->
new_worker = Task.async(fn -> crawling(queue_msg) end)
infinite_loop([new_worker | created_workers])
{:error, :empty} ->
created_workers.map(&Task.await/1)
end
end
Run Code Online (Sandbox Code Playgroud)
假如说:
crawling功能将创建另一个3Taskcrawling 工人都可以跑3秒钟queue可能有上百万的消息我怎么知道Elixir上并行处理的限制是什么?如何管理它不破坏?
我正在生成一些自动规范,并且我希望在期望成功的时候有一个自定义的成功消息。例如,我想要这样的报告:
Opportunity
.rating_info
where the real estate kind is Monoambiente
and there aren't assigned values
is 0
when there are multiple combinations
is has the expected value(run 45 different combinations)
Run Code Online (Sandbox Code Playgroud) 我正在学习AngularJs,但我无法使它成功.我读到了摘要周期,但对我来说并不清楚.很明显,这个代码失败了,因为进入一个无限循环,但我不知道如何解决它.有人能帮助我吗?
<!DOCTYPE html>
<html lang="eng" ng-app="test">
<head>
<title>Learning Angular</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular-route.js"></script>
<script type="text/javascript">
var app = angular.module('test', ['ngRoute']);
app.factory('visitCounterService', function () {
var counterService = function() {
var _count = 1;
var counter = function() { return _count++; };
return { counter: counter }
}();
return counterService;
});
app.service('homeModel', ['visitCounterService', function(visitCounterService){
this.getTitle = function() {
var n = visitCounterService.counter();
return "Welcome to this awesome demo. You are the visitor n° " + n;
};
}]);
app.controller('homeController', ['$scope', 'homeModel', …Run Code Online (Sandbox Code Playgroud)