我有两个型号,Courier和Order.
我在下面有以下查询:
active_couriers = Courier.
available_courier_status.
where(:service_region_id => @service_region.id).
includes(:orders)
Run Code Online (Sandbox Code Playgroud)
但是,此查询有效,它会提取所有订单.我想将订单限制为当天的订单.所以我添加了以下查询where("orders.created_at >= ?", Time.zone.now.beginning_of_day).
active_couriers = Courier.
available_courier_status.
where(:service_region_id => @service_region.id).
includes(:current_orders).
includes(:orders).
where("orders.created_at >= ?", Time.zone.now.beginning_of_day)
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "orders"
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
我试图读取并解析一个以数组(例如[{test: "test"}])开头的JSON字符串,并继续遇到错误:
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
Run Code Online (Sandbox Code Playgroud)
我的日志中的错误指向此行:
Gson gson = new GsonBuilder().create();
PayoutCharges payoutList = gson.fromJson(reader, PayoutCharges.class);
Run Code Online (Sandbox Code Playgroud)
在一些stackoverflow答案之后,我创建了PayoutCharges类作为PayoutCharge的数组列表.如何解决此问题,以便GSON知道JSON字符串在数组中?
PayoutCharges.java
package com.app.driver.entity;
import java.util.ArrayList;
import com.google.gson.annotations.SerializedName;
public class PayoutCharges {
//handle error
@SerializedName("error")
private Error mError;
public Error getError() {
return mError;
}
public void setError(Error error) {
mError = error;
}
//handle data
@SerializedName("payoutCharges")
private ArrayList<PayoutCharge> mPayoutCharges;
public ArrayList<PayoutCharge> getPayoutCharges() {
return mPayoutCharges;
}
public void setPayoutCharges(ArrayList<PayoutCharge> payoutCharges) { …Run Code Online (Sandbox Code Playgroud) 在我为项目添加更多关系后,我收到此跟随错误.在localhost上,页面显示完全正常.但是,在尝试在heroku上查看时出现错误.
ActiveRecord::StatementInvalid (PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
Run Code Online (Sandbox Code Playgroud)
这是我的traveldeal控制器:
def show
@traveldeal = @commentable = Traveldeal.find(params[:id])
@comments = Comment.all
@title = @traveldeal.title
@eventdeals = Eventdeal.tagged_with(@traveldeal.location_tag_list, :any => true, :order => 'RANDOM()', :limit => 3)
end
Run Code Online (Sandbox Code Playgroud)
traveldeal/show.html
<% unless @eventdeals.blank? %>
<h1>Events in the area:</h1>
<% @eventdeals.each do |eventdeal| %>
<%= link_to eventdeal do %>
<!-- content -->
<% end %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
Heroku日志
SELECT DISTINCT eventdeals.* FROM "eventdeals" JOIN …
postgresql ruby-on-rails heroku acts-as-taggable-on ruby-on-rails-3
我正在尝试使用自己的JSON解析器.我有一个我想要标记的输入字符串:
input = "{ \"foo\": \"bar\", \"num\": 3}"
如何删除转义字符\,使其不是我的令牌的一部分?
目前,我使用的解决方案delete:
tokens = input.delete('\\"').split("")
=> ["{", " ", "f", "o", "o", ":", " ", "b", "a", "r", ",", " ", "n", "u", "m", ":", " ", "3", "}"]
但是,当我尝试使用时gsub,它找不到任何东西\".
tokens = input.gsub('\\"', '').split("")
=> ["{", " ", "\"", "f", "o", "o", "\"", ":", " ", "\"", "b", "a", "r", "\"", ",", " ", "\"", "n", "u", "m", "\"", ":", " ", "3", "}"] …
我正在尝试编写集成测试,如果用户单击按钮,它会在数据库中创建一条新记录(CheckPrice模型).
我nil is not a symbol尝试运行测试时遇到错误.
require 'spec_helper'
describe 'CheckPrice', type: :request, js: true do
it "should create a new CheckPrice record when user clicks Check Price on topic page" do
city = create :city
hotel = create :hotel
affiliate_link = create :affiliate_link
visit '/hotel-bilboa-hotel'
sleep 2
click_button "Check Prices"
response.should change(CheckPrice.count).by(1)
end
end
Run Code Online (Sandbox Code Playgroud)
单击"检查价格"时,会有一个事件侦听器触发checkprices_controller中的新方法.
错误似乎发生在最后一行response.should change(CheckPrice.count).by(1).看起来该方法无法识别模型CheckPrice.如何引用CheckPrice表?
谢谢.
我在我的rails应用程序中有一个mongo查询,因为该集合非常庞大.
FbCheckin.where(ext_fb_place_id: self.ext_fb_place_id).all
Run Code Online (Sandbox Code Playgroud)
我从文档中读到,您可以添加一个timeout选项,以防止光标超时,并显示以下消息:
Moped::Errors::CursorNotFound: The operation: "GET MORE" failed with error
Run Code Online (Sandbox Code Playgroud)
我尝试了几种方法,包括
FbCheckin.where(ext_fb_place_id: ext_fb_place_id, {:timeout=>false}).all
Run Code Online (Sandbox Code Playgroud)
和
FbCheckin.find(ext_fb_place_id: ext_fb_place_id, {:timeout=>false}).all
Run Code Online (Sandbox Code Playgroud)
但这些都不会阻止光标超时.
有谁知道我怎么能做这个查询并收集所有FbCheckins没有光标超时事先?
谢谢
我正在阅读可用于标记的Github文档, https://github.com/mbleigh/acts-as-taggable-on,我想强制标记保存为小写.配置部分中的说明表示添加该行
ActsAsTaggableOn.force_lowercase = true
但我不太确定这会发生什么.
我应该把这段代码放在什么文件中?
谢谢!
我目前正在尝试使用 React 客户端设置 Node/Express 应用程序以与其交互。我设置了通行证来处理 JWT 的身份验证。当用户登录时,我验证电子邮件/密码。然后我设置cookie:
res.cookie('jwt', token, { httpOnly: true, secure: false });
Run Code Online (Sandbox Code Playgroud)
我看到令牌在响应标头中被传回,但是当我在开发者工具 > 应用程序 > Cookies 下检查 Chrome 浏览器的 cookie 时,我看到一个空的 cookie。我做错了什么,如何在后续请求的响应头中发送 jwt?
服务器/App.js
const app = express()
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.post('/login', (req, res) => {
passport.authenticate('local', { session: false }, (error, user) => {
if (error || !user) {
res.status(400).json({ error });
}
// Construct JWT payload
const payload = { …Run Code Online (Sandbox Code Playgroud) 我最近添加了e.preventDefault()一个我的javascript函数,它打破了我的茉莉花规格.我试过spyOn(e, 'preventDefault').andReturn(true);但我得到的e是未定义的错误.我怎么存根e.preventDefault()?
showTopic: function(e) {
e.preventDefault();
midParent.prototype.showTopic.call(this, this.model, popup);
this.topic.render();
}
it("calls the parent", function() {
var parentSpy = spyOn(midParent.prototype, "showTopic");
this.view.topic = {
render: function() {}
};
this.view.showTopic();
expect(parentSpy).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试测试具有异步调用的操作.我使用Thunk作为我的中间件.在下面的操作中,如果服务器返回OK响应,我只会调度和更新存储.
export const SET_SUBSCRIBED = 'SET_SUBSCRIBED'
export const setSubscribed = (subscribed) => {
return function(dispatch) {
var url = 'https://api.github.com/users/1/repos';
return fetch(url, {method: 'GET'})
.then(function(result) {
if (result.status === 200) {
dispatch({
type: SET_SUBSCRIBED,
subscribed: subscribed
})
return 'result'
}
return 'failed' //todo
}, function(error) {
return 'error'
})
}
}
Run Code Online (Sandbox Code Playgroud)
我在编写测试时遇到问题,调试要么调用调用,要么不调用(取决于服务器响应),或者我可以让调用操作并检查存储中的值是否正确更新.
我使用fetch-mock来模拟web的fetch()实现.但是,看起来我的代码块then不会执行.我也试过在这里使用这个例子没有运气 - http://redux.js.org/docs/recipes/WritingTests.html
const middlewares = [ thunk ]
const mockStore = configureStore(middlewares)
//passing test
it('returns SET_SUBSCRIBED type and subscribed true', () => { …Run Code Online (Sandbox Code Playgroud)