小编shi*_*las的帖子

如何使用ActiveRecord :: Relation数组初始化ActiveModel :: Serializer类?

我有一个序列化器

class FundingSerializer < ActiveModel::Serializer
  attributes :id, 

  has_one :user
  has_one :tournament
  embed :ids, include: true
end
Run Code Online (Sandbox Code Playgroud)

用适当的关联初始化

FundingSerializer.new(Funding.first).to_json
Run Code Online (Sandbox Code Playgroud)

产量

"{\"users\":[{\"id\":2,\"first_name\":\"Nick\"}],\"tournaments\":[{\"id\":1,\"end_date\":\"2013-07-21T23:18:54.981Z\",\"start_date\":\"2013-07-14T23:18:54.980Z\"}],\"funding\":{\"id\":1}}"
Run Code Online (Sandbox Code Playgroud)

但,

FundingSerializer.new(Funding.all).to_json
Run Code Online (Sandbox Code Playgroud)

得到这个错误.

undefined method `read_attribute_for_serialization' for #<ActiveRecord::Relation::ActiveRecord_Relation_Funding:0x007f998910a250>
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:121:in `method_missing'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:68:in `method_missing'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:99:in `block in attribute'
    from (eval):3:in `_fast_attributes'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:466:in `rescue in attributes'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:454:in `attributes'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:478:in `_serializable_hash'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:360:in `serializable_hash'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:344:in `as_json'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activesupport-4.0.0/lib/active_support/json/encoding.rb:50:in `block in encode'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activesupport-4.0.0/lib/active_support/json/encoding.rb:81:in `check_for_circular_references'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activesupport-4.0.0/lib/active_support/json/encoding.rb:49:in `encode'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activesupport-4.0.0/lib/active_support/json/encoding.rb:34:in `encode'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/activesupport-4.0.0/lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
    from /Users/nicholasshook/.rvm/gems/ruby-2.0.0-p247@pokerfund/gems/active_model_serializers-0.8.1/lib/active_model/serializer.rb:333:in `to_json'
    from …
Run Code Online (Sandbox Code Playgroud)

active-model-serializers ruby-on-rails-4

45
推荐指数
6
解决办法
3万
查看次数

ruby haml中链接后的标点符号

我有这个代码:

%p
   A debtor with the court's approval can hire attorneys via
   %a{:id=>"proc",:href=>'/codes#rule327'}Section 327.
Run Code Online (Sandbox Code Playgroud)

这呈现:

经法院批准的债务人可以通过第327条聘请律师.

我知道这是非常挑剔的,但我不希望这个时期加粗.当我尝试:

%p
   A debtor with the court's approval can hire attorneys via
   %a{:id=>"proc",:href=>'/codes#rule327'}Section 327
   \.
Run Code Online (Sandbox Code Playgroud)

它产生:

经法院批准的债务人可以通过第327条聘请律师.

我想知道如何获得:

经法院批准的债务人可以通过第327条聘请律师.

ruby haml

16
推荐指数
2
解决办法
2827
查看次数

如何在Sourcetree中使用Git Rebase?

我希望我的本地主分支包含提交'fixed js errors'并重新定位到origin/master.
在此输入图像描述

我开始这样的过程: 在此输入图像描述

这让我想到了这个: 我的Sourcetree

但正如你所看到的,在我推动之前,我被要求拉.每次我拉动时,我都会遇到第一张图片中描绘的情况.我究竟做错了什么?!谢谢,

git atlassian-sourcetree

11
推荐指数
1
解决办法
2万
查看次数

如何使用和实例变量和HTTParty发布到使用OAuth2的API

我可以通过以下方式从Oauth2 API获取信息:

token = "Token I get from authenticating my App"
auth = "Bearer " + token
user = HTTParty.get("API Website", :headers => { "Authorization" => auth})
Run Code Online (Sandbox Code Playgroud)

我将如何发布到我的应用中生成的API内容?我有一个实例变量:

@contact = {"contact": {"name": "John Doe"  }}
Run Code Online (Sandbox Code Playgroud)

我试过这个:

token = "Token I get from authenticating my App"
auth = "Bearer " + token
user = HTTParty.get("API Website", :headers => { "Authorization" => auth}, @contact)
Run Code Online (Sandbox Code Playgroud)

无济于事.

ruby httparty oauth-2.0

10
推荐指数
1
解决办法
5187
查看次数

Ember fastboot适用于http api主机,但不适用于https主机

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  host: 'http://api.theapothecaryshoppe.com',
  // host: 'https://api.theapothecaryshoppe.com'
});
Run Code Online (Sandbox Code Playgroud)

常规主机工作,但当我使用https时,我收到此错误:

Error: The adapter operation was aborted
at EmberError.AdapterError (/home/nick/the-apothecary-shoppe/portal-ember/tmp/broccoli_merge_trees-output_path-j1H7NK9S.tmp/fastboot/vendor.js:85927:16)
at EmberError.ErrorClass (/home/nick/the-apothecary-shoppe/portal-ember/tmp/broccoli_merge_trees-output_path-j1H7NK9S.tmp/fastboot/vendor.js:85952:24)
at ajaxError (/home/nick/the-apothecary-shoppe/portal-ember/tmp/broccoli_merge_trees-output_path-j1H7NK9S.tmp/fastboot/vendor.js:87597:15)
at Object.hash.error (/home/nick/the-apothecary-shoppe/portal-ember/tmp/broccoli_merge_trees-output_path-j1H7NK9S.tmp/fastboot/vendor.js:87269:23)
at fire (/home/nick/the-apothecary-shoppe/portal-ember/node_modules/jquery-deferred/lib/jquery-callbacks.js:78:30)
at Object.fireWith (/home/nick/the-apothecary-shoppe/portal-ember/node_modules/jquery-deferred/lib/jquery-callbacks.js:188:7)
at Object.fire [as reject] (/home/nick/the-apothecary-shoppe/portal-ember/node_modules/jquery-deferred/lib/jquery-callbacks.js:195:10)
at ClientRequest.onError (/home/nick/the-apothecary-shoppe/portal-ember/node_modules/najax/lib/najax.js:208:9)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:309:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Run Code Online (Sandbox Code Playgroud)

有什么想法?这让我非常困惑.

javascript ssl-certificate ember.js

6
推荐指数
1
解决办法
315
查看次数

将帖子数据传递到Sinatra的其他页面

这似乎工作正常:

意见/ index.haml:

%form{:method => 'POST' :action => '/'}
  %label{:for => 'name'} Name:
    %input{:type => 'text, :value => @values[:name] || ""}
  %input{:type => 'submit'}
Run Code Online (Sandbox Code Playgroud)

app.rb:

post '/' do
  @values = params
  haml :review
end
Run Code Online (Sandbox Code Playgroud)

意见/ review.rb

Hello #{params[:name]}!
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将我的后期数据发送到不同URL上的相同视图时,我收到错误,或者换句话说:

app.rb:

post '/' do
  @values = params
  redirect '/review'
end

get '/review' do
  @values = params
  haml :review
end
Run Code Online (Sandbox Code Playgroud)

数据未通过,但未引发错误.

如何在这样的页面之间发送后期数据?理想情况下,我不想创建数据库.

ruby sinatra

5
推荐指数
1
解决办法
6787
查看次数

Grunt Build不与Bower安装的组件一起使用

我想跑

grunt build
Run Code Online (Sandbox Code Playgroud)

来自创建的目录

yo angular
Run Code Online (Sandbox Code Playgroud)

我通过凉亭安装了angular-ui-bootstrap.本地我需要添加

<script src="components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

到我的index.html和

angular.module('app', ['ngResource', 'ngCookies', 'ui.bootstrap'])
Run Code Online (Sandbox Code Playgroud)

到我的app.js. 但是每次我尝试构建应用程序时都会出现此错误

错误:没有模块:ui.bootstrap在Error()atUsers/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:1104:17 at ensure(/ Users/nicholasshook/angular/pokerfund/angular_app /app/components/angular/angular.js:1045:38)在/ Users/nicholasshook/angular模块(/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:1102:14) /pokerfund/angular_app/app/components/angular/angular.js:2768:24位于forEach的Array.forEach(native)(/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:131 :11)在/ Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular的loadModules(/Users/nicholasshook/angular/pokerfund/angular_app/app/components/angular/angular.js:2764:5) .js:2769:38在Array.forEach(native)TypeError:无法读取null的属性'awesomeThings'.(/Users/nicholasshook/angular/pokerfund/angular_app/test/spec/controllers/main.js:20:17)

angularjs gruntjs yeoman angular-ui-bootstrap

3
推荐指数
1
解决办法
5932
查看次数

尝试关闭elasticsearch集群时IndexPrimaryShardNotAllocatedException错误

用我的机器上安装elasticsearch后https://gist.github.com/wingdspur/2026107它开始于一个elasticsearch集群http://localhost:9200,我试图创建设置的指标,并使用此代码:

  search_indices.create index: 'test'
  search_indices.refresh index: 'test'
  search_indices.close index: 'test'
  search_indices.put_settings(index: 'test', **my_index_settings)
  search_indices.put_mapping(index: 'test', **my_mapping_settings)
  search_indices.open index: 'test'
Run Code Online (Sandbox Code Playgroud)

哪里

search_indices = Elasticsearch::Client.new({host: 'http://localhost:9200'}).indices
# this module comes from the elasticsearch-ruby gem
Run Code Online (Sandbox Code Playgroud)

当我执行此代码时,当我尝试执行'close'方法时,我收到错误(上面的第3行)

Elasticsearch::Transport::Transport::Errors::Conflict:
   [409] {"error":"IndexPrimaryShardNotAllocatedException[[test_1] primary not allocated post api]","status":409}
Run Code Online (Sandbox Code Playgroud)

我尝试添加刷新方法(上面的第2行),有时可以工作,有时不工作,我有一种感觉,"有时工作"意味着我做错了什么.谢谢您的帮助!

ruby elasticsearch

3
推荐指数
1
解决办法
1283
查看次数

简单覆盖路线未显示

我有一个rails应用程序,当我运行我的测试时,我在my/cov文件夹中创建新文件

Finished in 20.6 seconds
19 examples, 0 failures
Coverage report generated for RSpec to /Users/nicholasshook/Sites/<<my project>>/coverage. 264 / 446 LOC (59.19%) covered.
Run Code Online (Sandbox Code Playgroud)

完成.

但是,当我尝试访问localhost/coverage/index.html时,我收到此错误

No route matches [GET] "/coverage/index.html"
Run Code Online (Sandbox Code Playgroud)

谢谢

ruby-on-rails

2
推荐指数
1
解决办法
2585
查看次数

Nokogiri中的HTML元素之间的空格:: HTML#content

当我跑这个

Nokogiri::HTML('<div class="content"><p>Hello</p><p>Good Sir</p></div>').content
Run Code Online (Sandbox Code Playgroud)

我明白了

"HelloGood Sir"
Run Code Online (Sandbox Code Playgroud)

有没有办法通过Nokogiri的API获得以下内容?

"Hello Good Sir"
Run Code Online (Sandbox Code Playgroud)

ruby nokogiri

1
推荐指数
1
解决办法
363
查看次数