我已经阅读了大量教程和文档,但是当 Firestore 中的数据发生变化时,似乎无法在页面上更新(注意:不是 Firebase)
这是我目前工作正常的内容,除非数据库中的数据发生变化,除非我刷新,否则它不会反映在页面本身上。下面的代码在脚本标签内:
import { recipeRef } from '../../firebase';
export default {
data() {
return {
recipes: []
}
},
firestore: {
recipes: recipeRef
},
created() {
db.collection('recipes').get().then((onSnapshot) => {
this.loading = false
onSnapshot.forEach((doc) => {
let data = {
'id': doc.id,
'name': doc.data().name
}
this.recipes.push(data)
})
})
}
Run Code Online (Sandbox Code Playgroud)
我没有使用 Vuex。添加数据、编辑和阅读工作正常。只是不反映数据更改后的更改。也许我应该使用一个生命周期钩子?对于“ onSnapshot” - 我试过“ snap”,“ querySnapshot”等。没有运气。
提前致谢。
我一直在跟踪postgres全文搜索的railscast,但我一直收到以下错误
未定义的局部变量或方法`scoped'for#
我完全按照轨道直播.我安装了所有正确的宝石.(pg_search,pg).这是我的代码
文章控制器(我也在这里使用acts_as_taggable)
def index
@articles = Article.text_search(params[:query]).page(params[:page]).per_page(3)
if params[:tag]
@articles = Article.tagged_with(params[:tag])
else
@articles = Article.all
end
end
Run Code Online (Sandbox Code Playgroud)
文章模型
def self.text_search(query)
if query.present?
where("name @@ :q or content @@ :q", q: query)
else
scoped
end
end
Run Code Online (Sandbox Code Playgroud)
和Article/index上的表格
<%= form_tag articles_path, method: :get do %>
<p>
<%= text_field_tag :query, params[:query] %>
<%= submit_tag "Search", name: nil %>
</p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我在railscast代码和我之间注意到的唯一区别是他使用了will_paginate,但当我将控制器更改为
@articles = Article.text_search(params[:query])
Run Code Online (Sandbox Code Playgroud)
没什么区别.
我几乎到处搜索但无济于事.
我试图在rails 4网站上加载广告并继续收到以下错误
onejs?MarketPlace=US&adInstanceId=xxxxxxxx&storeId=xxxxxxx:1 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
Run Code Online (Sandbox Code Playgroud)
如果我刷新页面广告加载就好了.以下是来自amazon的广告代码,该代码位于show.html.erb文件中.
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=xxxxxxxxx&storeId=xxxxxxxx"></script>
Run Code Online (Sandbox Code Playgroud)
如果我使用带有iframe代码的亚马逊广告没有问题,但此格式广告没有iframe选项(这是原生广告 - 扫描相关内容的页面以展示广告)
它是一个rails 4站点,在heroku上启用了turbolinks.我完全不知道如何解决它.这也发生在adwords和media.net广告上.
知道怎么解决?
我试图使用与成分具有has_many关系的食谱来种植我的数据库.成分表有4行.但是我的代码却遇到了错误.这是我的代码.我对rails很新,但还没找到解决方案.我正在使用Rails 4和Postgres.
错误
rake aborted!
Ingredient(#xxxxxxx) expected, got Hash(#xxxxxxx)
Tasks: TOP => db:seed
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
食谱
class Recipe < ActiveRecord::Base
attr_accessible :title, :descrition, :image
has_many :ingredients
accepts_nested_attributes_for :ingredients
end
Run Code Online (Sandbox Code Playgroud)
成分
class Ingredient < ActiveRecord::Base
attr_accessible :measure, :modifier, :item, :note
belongs_to :recipe
end
Run Code Online (Sandbox Code Playgroud)
Seed.rb(这里的例子有2种成分,每种成分的每一行都有含量)
Recipe.create(
[{
title: "Recipe title here",
description: "This is the description",
image: "theimage.jpg",
ingredients_attributes: [{measure: "1cup", modifier: "canned", item: "Mushrooms", note: "drained"}, {measure: "1lb", modifier: "sliced", item: "Bacon", note: "previously cooked"},] …Run Code Online (Sandbox Code Playgroud) postgresql ×2
ruby ×2
amazonads ×1
firebase ×1
heroku ×1
javascript ×1
railscasts ×1
vue.js ×1