我跑rails s或bundle exec rails s我得到这个警告:
Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub rails` to work around a system/bundle conflict.
Run Code Online (Sandbox Code Playgroud)
这是什么意思?通过查看bundler站点,我对binstubs的理解是你可以为它们设置可执行文件,所以不用运行bundle exec blabla就可以了bin/blabla.所以这个错误说我bundler没有设置正确的binstub?
当我运行时,bundle binstub rails我得到了这个输出
rails has no executables, but you may want one from a gem it depends on.
railties has: rails
bundler has: bundle, bundler
Run Code Online (Sandbox Code Playgroud)
我不明白我的系统试图告诉我什么,它并没有破坏任何东西,但我有预感如果我不解决它可能会变成一个更大的问题
ruby 2.0.0p247
Run Code Online (Sandbox Code Playgroud)
哪个红宝石 …
我想使用gulp-connect的所有请求转发给api/到localhost:3000.我在https://github.com/AveVlad/gulp-connect/issues/27上找到了一个例子
并设置我的连接任务,如下所示:
gulp.task('connect', function(){
connect.server({
root: './app',
middleware: function(connect, o) {
return [ (function() {
var url = require('url');
var proxy = require('proxy-middleware');
var options = url.parse('http://localhost:3000/api');
options.route = 'api';
return proxy(options);
})()]
}
});
});
Run Code Online (Sandbox Code Playgroud)
运行此任务会发出警告,connect deprecated connect(middleware): use app.use(middleware) instead node_modules/gulp-connect/index.js:39:19此任务不会按预期转发请求.
我查看了connect源代码,看看我是否可以解决折旧问题,但它超出了我在js中的水平:
ConnectApp.prototype.server = function() {
var app, middleware;
middleware = this.middleware();
app = connect.apply(null, middleware);
server = http.createServer(app);
app.use(connect.directory(typeof opt.root === "object" ? opt.root[0] : …Run Code Online (Sandbox Code Playgroud) 我正在按照Jest教程测试一个react组件,并且遇到了jsx的预处理问题.我假设错误是由于预处理,错误消息不是很有帮助.谷歌搜索显示与旧版本的react/jest相似的错误,这些错误是通过包含/** @jsx React.DOM */docblock来修复的,据我所知,docblock是固定的.
当我运行我的测试时:
Using Jest CLI v0.8.0, jasmine1
FAIL spec/MyComponent_spec.js
Runtime Error
SyntaxError: /Users/asdf/react/stuff-react/spec/MyComponent_spec.js: Unexpected token (13:6)
npm ERR! Test failed. See above for more details.
Run Code Online (Sandbox Code Playgroud)
有问题的行是应该渲染我的组件的行:
jest.dontMock('../src/MyComponent');
let React = require('react');
let ReactDOM = require('react-dom');
let TestUtils = require('react-addons-test-utils');
const MyComponent = require('../src/MyComponent');
describe('MyComponent', function(){
it('render', function(){
var myComponent = TestUtils.renderIntoDocument(
// This is the line referenced in the test error
<MyComponent />
)
var myComponentNode = ReactDOM.findDOMNode(myComponent);
expect(myComponentNode.textContent).toEqual('hi');
});
});
Run Code Online (Sandbox Code Playgroud)
我以为我package.json …
我正在尝试测试一个使用的应用程序gem devise_token_auth,它基本上包括几乎每个请求上的几个额外的数据库读/写(以验证和更新用户访问令牌).
除了在测试包含几个额外的db读/写的控制器操作时,一切正常.在这些情况下,终端锁定,我被迫通过活动监视器杀死ruby进程.
有时我得到这样的错误消息:
ruby /Users/evan/.rvm/gems/ruby-2.1.1/bin/rspec spec/controllers/api/v1/messages_controller_spec.rb(1245,0x7fff792bf310) malloc: *** error for object 0x7ff15fb73c00: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)
我不知道如何解释.我90%确定问题是由于这个gem以及它在每个请求中引起的额外数据库活动,因为当我恢复到之前的,不那么密集的身份验证时,所有问题都会消失.我还通过给予postgres一些额外的时间来处理违规测试,从而使事情得到控制:
after :each do
sleep 2
end
Run Code Online (Sandbox Code Playgroud)
这适用于除一个之外的所有情况,这需要在之前超时expect,否则会抛出此错误:
Failure/Error: expect(@user1.received_messages.first.read?).to eq true
ActiveRecord::StatementInvalid:
PG::UnableToSend: another command is already in progress
: SELECT "messages".* FROM "messages" WHERE "messages"."receiver_id" = $1 ORDER BY "messages"."id" ASC LIMIT 1
Run Code Online (Sandbox Code Playgroud)
对我来说,再次指向数据库问题.
还有什么我可以做的来追踪/控制这些错误吗?我应该研究一下任何rspec设置?
我在运行任何rails命令时遇到以下错误,rails s或者rails c它也阻止了我的heroku应用程序启动(同样的错误):
app/config/application.rb:7:in `<top (required)>': uninitialized constant Bundler (NameError)
from /Users/you/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `require'
Run Code Online (Sandbox Code Playgroud)
错误消息中的第7行是:
Bundler.require(:default, Rails.env)
Run Code Online (Sandbox Code Playgroud)
执行命令bundle exec rails s成功,但这对heroku应用程序没有帮助.我已经验证了which ruby,which rails并且which bundler.我也尝试启动一个新的rvm gemset并重新安装捆绑包.heroku错误相同:
/app/config/application.rb:7:in `<top (required)>': uninitialized constant Bundler (NameError)
Run Code Online (Sandbox Code Playgroud)
运行bundle check返回没有问题.
一些类似的问题表明:
bundle config --delete bin # Turn off Bundler's stub generator
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
Run Code Online (Sandbox Code Playgroud)
但我尝试了它并没有改变.我在Rails 4上
编辑:
我正在另一个应用程序中运行 …
我正在寻找一种从量角器返回一系列值的简单方法 all.(by.repeater)
基本上,我只想要一个简单的方法来制作一个usernames给定转发器的数组user in users.
现在我正在构建它:
allUsers = element.all(by.repeater('user in users').column('user.username')).then(function(array){
var results = []
var elemLength = array.length
for(var n = 0; n < elemLength; n++){
array[n].getText().then(function(username){
results.push(username)
})
}
return results
});
expect(allUsers).toContain(newUser)
Run Code Online (Sandbox Code Playgroud)
是否有更简洁,可重复使用的方法来构建量角器/茉莉花,我找不到?
我的索引页之一在多个页面上显示了相同的资源,扩展名为will_paginate. 我还有其他页面分页完美,但无法找出问题所在。
在我的模型中我有这个方法:
self.per_page = 10
def self.index_search(query)
if query.present?
self.approved.where("name ilike :q or ko_name ilike :q", q: "%#{query}%")
.order(date: :asc).group("id")
else
approved.upcoming.order(date: :asc).group("id")
end
end
Run Code Online (Sandbox Code Playgroud)
然后在控制器中:
def index
@events = Event.index_search(params[:query]).paginate(page: params[:page])
end
Run Code Online (Sandbox Code Playgroud)
并在视图中:
<%= will_paginate @events, renderer: BootstrapPagination::Rails %>
Run Code Online (Sandbox Code Playgroud)
通常,第一页上的最后一项会在第二页上的同一位置重复。
在研究了 StackOverflow 之后,我将 添加到了该.group("id")方法中,但我对下一步应该看什么感到困惑。
编辑:
如果我更改self.per_page = 10为大于 12 的数字,重复问题就会消失。我真的很想将其保持在每页 10 个。
编辑:所有事件都有一个date字段并且分页事件都具有相同的日期值也可能相关。
我正在尝试将selenium测试套件移植到capybara-webkit.Rails应用程序在rails视图中嵌入了一个角度应用程序,其行为与预期不符webkit.
像这样的测试:
需要'spec_helper'
feature 'Editing company profiles' do
before do
@user = create(:employee)
@company = Company.find(@user.employer.id)
sign_in_as! @user
end
scenario 'successfully', js: true do
click_link 'Dashboard'
click_link @company.name
click_button 'Edit'
fill_in 'company_name', with: 'new name'
click_button 'Save'
expect(page).to have_content "Your company profile has been updated!"
end
end
Run Code Online (Sandbox Code Playgroud)
会在selenium中没有问题,但是webkit我得到了错误
Failure/Error: Unable to find matching line from backtrace
ActionController::ParameterMissing:
param is missing or the value is empty: company
# ./app/controllers/api/v1/companies_controller.rb:23:in `company_params'
# ./app/controllers/api/v1/companies_controller.rb:10:in `update'
Run Code Online (Sandbox Code Playgroud)
缺少痕迹,可能是因为它来自有角度的土地,但错误是报告没有来自客户端的参数.我已经尝试了capybara-angular宝石,但它没有帮助.我也尝试用capybara保存页面,没有什么看起来不合适,有没有办法访问PATCH …
我正在玩插头路由器并试图在我的路由器中读取一个简单的帖子请求的正文:
表格
<form action="/create_item" method="post">
<input type="text" value="whatever" name="name">
<input type="number" value="99" name="age">
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
我的路由器
post("/create_item") do
{:ok, data, _conn} = read_body(conn)
send_resp(conn, 200, data)
end
Run Code Online (Sandbox Code Playgroud)
如果我提交我的表单,这将呈现name=input-value给页面,但然后我将不得不解析该字符串以获取值.这有点冒犯它的错误方法.
从我对elixir的小经验来看,似乎我应该做一些类似于模式匹配的东西从我的表单中read_body(conn)拉出每个key: value,但我在插件文档中找不到任何关于它的东西.我试图通过凤凰源寻找想法,但这有点超出了我的灵丹妙药的知识.有一个parse_form_data/1我缺少的明显功能吗?
我试图设置一个关于异步函数的返回值的监视,但继续运行到无限的摘要循环.这是我的$ watch
$scope.$watch(function(){
var friendsCount = PublicUserData().then(function(data){
console.log(data.length);
return data.length;
});
return friendsCount;
}, function(newValue, oldValue) {
console.log("change"+ newValue);
});
Run Code Online (Sandbox Code Playgroud)
我可以在chrome控制台中看到两者都console.log被调用,但第二个(在回调上)被调用的次数远远超过第一个.
PublicUserData用途$q:
.factory('PublicUserData', function($http, $q){
return function(){
var defer = $q.defer();
$http.get('/api/v1/users/').then(function(data){
defer.resolve(data.data.users);
})
return defer.promise;
}
})
Run Code Online (Sandbox Code Playgroud)
我尝试过一些东西,比如将watch表达式设置为我的$ scope范围$watch,但最终会返回工厂的代码,而不是工厂的返回值.
是否可以使用$watch实现承诺的函数?或者我应该使用其他东西?
我使用postgres的数组数据类型在rails中有一个标记系统.我正在尝试写一个scope会返回任何包含标签的帖子.到目前为止,我有这个范围工作:
scope :with_tag, ->(tag) { where("tags @> ARRAY[?]", tag) }
Run Code Online (Sandbox Code Playgroud)
我想扩展这个范围,以便我可以同时查询多个标签,理想情况如下:
Post.with_tags(['some', 'tags', 'to', 'query'])
Run Code Online (Sandbox Code Playgroud)
哪个会返回任何Post有这些标签的人.我已经考虑过创建一个类方法来处理输入数组的迭代:
def self.with_tags(args)
# start with empty activerecord relation
# want to output AR relation
results = Post.none
args.each do |tag|
results = results.concat(Post.with_tag(tag))
end
results.flatten
end
Run Code Online (Sandbox Code Playgroud)
但这种方法对我来说很有趣,因为它为每个参数创建了一个新的查询.它也不会返回一个ActiveRecord :: Relation,因为flatten我真的希望将它作为输出.
我可以在OR查询范围内完成我所追求的内容吗?
我花了一个半小时来解决我的应用程序,试图找出原因
User.articles
Run Code Online (Sandbox Code Playgroud)
扔错了.模型看起来没问题:
class User < ActiveRecord::Base
has_secure_password
has_many :articles
validates :email, presence: true, uniqueness: true
validates :name, presence: true, uniqueness: true
end
Run Code Online (Sandbox Code Playgroud)
和
class Article < ActiveRecord::Base
validates :title, presence: true, uniqueness: true
validates :content, presence: true
belongs_to :user
has_many :article_categories
has_many :categories, through: :article_categories
end
Run Code Online (Sandbox Code Playgroud)
最后,问题是文章的迁移没有这条线
t.belongs_to :user
Run Code Online (Sandbox Code Playgroud)
在此过程中,我还尝试将此行放在用户迁移中
t.has_many :articles
Run Code Online (Sandbox Code Playgroud)
但它犯了一个错误.
为什么迁移只需要belongs_to关系的一面而不是has_many?
angularjs ×3
bundler ×2
postgresql ×2
arrays ×1
elixir ×1
gulp ×1
jasmine ×1
javascript ×1
jestjs ×1
protractor ×1
reactjs ×1
rspec ×1
ruby ×1