我正在尝试发送我的前端应用程序json,如下所示:
{
facilities: [
{id: 5, name: 'happy days ranch', location: { address: '1424 Pastoral Lane', zipcode: '25245'}, instructor_ids: [2, 4, 9]}
],
instructors: [
{id: 4, name: 'Johnny Pheonix', skill: '8', picture: 'aws_url', facility_ids: [5, 8, 12}
]
}
Run Code Online (Sandbox Code Playgroud)
render :json => @facilities
Run Code Online (Sandbox Code Playgroud)
串行器发现了这一点.好极了!但这并不包括任何教师
render :json => {facilities: @facilities, instructors: @instructors}
Run Code Online (Sandbox Code Playgroud)
这给了我一个教师数组和一个工具数组,但是没有使用activeModel :: Serializers.
render :json => [@facilities, @instructors]
Run Code Online (Sandbox Code Playgroud)
起初我很兴奋这个,因为它给了我两个数组,它使用了ActiveModel :: Serializers.但是,这就是JSON的样子:
{facilities: [
{facilities: [
#my facilities data
]},
{facilities: [
#my instructor data
]}
]}
Run Code Online (Sandbox Code Playgroud)
json activemodel ruby-on-rails-3 ember.js active-model-serializers
我正在尝试将我的应用程序从Ember Appkit移动到ember-cli,我无法复制以前由APIMethod和proxyURL方法提供的代理功能.
我正在启动服务器代理到localhost:3000
ember serve --proxy http://localhost:3000/
这将正确地从rails服务器读取我的数据.但是,当我尝试写入服务器时,我收到一条错误消息
POST http://localhost:4200/api/v1/posts 408 (Request Time-out)
它正试图发布到端口4200,这是服务于它的ember应用程序,但我希望它发布到端口3000.我怎么能这样做呢?
我正在使用ember-cli 0.28,ember 1.5.1,ember-data 1.0.0-beta.7和rails 4.1.
我正试图在Torii中使用github-oauth2提供程序,但我很难理解我应该如何设置一些回调.我将跟踪我正在使用的代码,以及我对它的理解,并希望这可以帮助确定我出错的地方.
首先,在我的行动中,我正在调用torii的open方法,就像它在文档中所说的那样:
this.get('torii').open('github-oauth2').then((data) => {
this.transitionTo('dashboard')
})
Run Code Online (Sandbox Code Playgroud)
当然,我在我的设置中有以下设置config/environment.js:
var ENV = {
torii: {
// a 'session' property will be injected on routes and controllers
sessionServiceName: 'session',
providers: {
'github-oauth2': {
apiKey: 'my key',
redirectUri: 'http://127.0.0.1:3000/github_auth'
}
}
},
}
Run Code Online (Sandbox Code Playgroud)
redirectUri用于我的Rails服务器.我在我的github应用程序上有相同的redirectUri设置,所以它们匹配.
这是我在服务器上的内容.这可能就是问题所在.我会在最后得到症状.
def github
client_id = 'my id'
client_secret = 'my secret'
code = params[:code]
@result = HTTParty.post("https://github.com/login/oauth/access_token?client_id=#{client_id}&client_secret=#{client_secret}&code=#{code}")
@access_token = @result.parsed_response.split('&')[0].split('=')[1]
render json: {access_token: @access_token}
end
Run Code Online (Sandbox Code Playgroud)
所以我发布到github的access_token端点,就像我应该的那样,我得到一个带有访问令牌的结果.然后我将该访问令牌打包为json.
结果是torii弹出窗口转到rails页面:
不幸的是,我所希望的是torii弹出窗口消失,给我的应用程序access_token,并让代码继续前进并执行我的then块中的代码.
我哪里错了?
我正在尝试在dc.js中创建一个饼图图例.但是,没有传说.它只是...没有显示出来.一切都和我使用legend命令之前一样.
这是传说代码:
.legend(dc.legend().x(80).y(70).itemHeight(13).gap(5));
Run Code Online (Sandbox Code Playgroud)
以下是相关代码的其余部分:
var companyDimension = data.dimension(function(d) {return d.company;});
var totalSalesByCompany = companyDimension.group().reduceSum(function(d) {return d.total;});
var pieChartCompanySales = dc.pieChart("#pie-chart-sales-by-company");
pieChartCompanySales
.width(150).height(150)
.dimension(companyDimension)
.group(totalSalesByCompany)
.legend(dc.legend().x(80).y(70).itemHeight(13).gap(5));
dc.renderAll();
Run Code Online (Sandbox Code Playgroud)
我试图在crossfilter中使用过滤器,但是没有.
这是最相关的代码:
var userDimension = data.dimension(function(d) {return d.user;}).filter(['John', 'Paul']);
var totalSalesByUser = userDimension.group();
var pieChartUserSales = dc.pieChart("#pie-chart-sales-by-user");
pieChartUserSales
.width(150).height(150)
.dimension(userDimension)
.group(totalSalesByUser);
dc.renderAll();
Run Code Online (Sandbox Code Playgroud)
饼图在使用和不使用过滤器时看起来相同,但我正在寻找的效果是将其缩小到John或Paul是用户的项目.
ember.js ×3
d3.js ×2
dc.js ×2
javascript ×2
pie-chart ×2
activemodel ×1
crossfilter ×1
ember-cli ×1
github-api ×1
json ×1
legend ×1
oauth-2.0 ×1
proxy ×1
torii ×1