Tag: postgresql

从Scratch标记:查询数据库问题

@saverio成功回答了关于从Scratch标记的数据库查询问题:标签云问题 现在我正在尝试将标记系统与jQuery-tokenInput连接到动态创建和查找标签,如http://railscasts.com/episodes/258-token-fields-revised 。 我的猜测是Posgresql数据库的查询问题。 我已经正确安装了Postgresql jQuery-tokenInput位于Application.js //= require jquery.tokeninput 不知何故,它可以从数据库中已有的标签加载标签,但它无法动态查询下面在pictures.js.coffee代码上列出的相同单词。 遵循所有相关范围: pictures.js.coffee jQuery -> $(‘#picture_tag_tokens’).tokenInput ‘/tags.json’ theme: ‘facebook’ prePopulate: $(‘#picture_tag_tokens’).data(‘load’) /views/pictures/_form 在这里,我的逻辑有点迷失 /models/picture.rb class Picture < ActiveRecord::Base attr_accessible :description, :title, :tag_tokens has_many :taggings has_many :tags, through: :taggings attr_reader :tag_tokens #The **below** is the relevant part for the #view/pictures/_form def tag_tokens=(tokens) self.tag_ids = Tag.ids_from_tokens(tokens) end def […]

Heroku – ActionView :: Template :: Error(PG ::错误:错误:列category_products.desc不存在

我正在使用RailsAdmin,这是我在RailsAdmin中单击我的模型CategoryProduct时出现的错误。 这就是错误的样子: Started GET “/admin/category_product” for 67.230.41.62 at 2012-12-21 23:20:07 +0000 2012-12-21T23:20:07+00:00 app[web.1]: 2012-12-21T23:20:07+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: column category_products.desc does not exist 2012-12-21T23:20:07+00:00 app[web.1]: LINE 1: …ry_products”.* FROM “category_products” ORDER BY category_p… 2012-12-21T23:20:07+00:00 app[web.1]: ^ 2012-12-21T23:20:07+00:00 app[web.1]: : SELECT “category_products”.* FROM “category_products” ORDER BY category_products. desc LIMIT 20 OFFSET 0): 2012-12-21T23:20:07+00:00 app[web.1]: 120: %tbody […]

Heroku加入/包括不像sqlite开发环境那样工作

所以这就是我在我的开发(SQLite)环境中完美运行的东西: key = “%#{keywords}%” listings = Listing.order(:headline) listings = listings.includes(:neighborhood).where(“headline like ? or neighborhoods.name like ?”, key, key) if keywords.present? 但是,当我在Heroku上尝试类似的东西时,我会遇到一些错误: listings = listings.includes(:neighborhood).where(“headline like ? or neighborhoods.name like ?”, key, key) ActiveRecord::ConfigurationError: Association named ‘neighborhoods’ was not found; perhaps you misspelled it? 我也尝试了以下内容并得到了相应的错误: > listings = Listing.includes(:neighborhood).where(“headline like :keywords or neighborhood.name like :keywords”, :keywords […]

RAILS / POSTGRESQL中的多个LIKE和AND运算符

我使用Rails 5.0.1和Postgresql作为我的数据库。 我有一个包含列的表:content包含单词。 问题:当我在找一个特定的单词时,我想看看这个单词是否包含我选择的字母(字符)。 假设我想要DB返回包含字母“a”,“b”和“c”的单词(所有这些单词,但没有特定的顺序) 我在做什么:我发现我可以使用Word.where(“content like ?”, “%a%”).where(“content like ?”, “%b%”).where(“content like ?”, “%c%”)或Word.where(“content like ? content like ? content like ?”, “%a%”, “%b%”, “%c%”)在这两种情况下即使我切换给定字母/子串的顺序它工作正常,例如。 两者都会找到“后退”,“出租车”等字样。 问题是:有没有更好/更干的方法呢? 如果想找到8个不同字母的单词怎么办? 我必须使用“喜欢的内容吗?” 8次? 是否可以将参数作为数组传递? (假设我不知道用户输入了多少个字母)

无法在Postgres数组列中保存Rails 4.2数组

我正在尝试在每个Dictionary模型上保存一组术语(我希望能够基本上搜索标签)。 所以terms = [“apple”,“pear”,“fruit”]可能是我试图在Dictionary模型的每个实例上保存的术语数组的一个例子。 以前,术语是序列化文本列。 然后我将其更改为尝试利用Postgres数组数据类型,如下所示。 当我尝试更新模型(例如,dictionary_example1.terms = [“fruit”,“pineapple”],然后调用save)时,所有存储的都是一个空数组[]。 我究竟做错了什么? Model.rb class Dictionary < ActiveRecord::Base serialize :terms, Array end schema.rb create_table “clinical_trials”, force: :cascade do |t| t.string “terms”, array: true end 移民 class ChangeTermsToArray < ActiveRecord::Migration def change change_column :dictionaries, :terms, "varchar[] USING (string_to_array(terms, ','))" end end

本地postrges工作,但似乎无法推动到RAILS_ENV =生产heroku

我的应用程序在localhost:3000上的本地环境中运行得很好。 它从我当地的postgres数据库中提取数据,但我似乎没有更新生产环境。 我的欢迎页面可以在我的https://gcl.herokuapp.com页面上查看,但是当我点击导航链接查看另一个页面时我收到错误,我假设因为该页面调用来自db的数据,它找不到。 我正在做$ rails db:migrate RAILS_ENV=production 我在终端中获得以下输出: (0.2ms) SELECT pg_try_advisory_lock(3666737882978712990); ActiveRecord::SchemaMigration Load (0.6ms) SELECT “schema_migrations”.* FROM “schema_migrations” ActiveRecord::InternalMetadata Load (0.6ms) SELECT “ar_internal_metadata”.* FROM “ar_internal_metadata” WHERE “ar_internal_metadata”.”key” = $1 LIMIT $2 [[“key”, :environment], [“LIMIT”, 1]] (0.2ms) BEGIN SQL (1.9ms) UPDATE “ar_internal_metadata” SET “value” = $1, “updated_at” = $2 WHERE “ar_internal_metadata”.”key” = $3 [[“value”, “production”], [“updated_at”, […]

在搜索分数时,这是正确的Rails查询吗?

我有以下查询…… CourseRegistration.where(status: “Completed”).where(“score >= ?”, “80”) 首先,是的,得分字段是数据库中的字符串。 这[大部分]有效,然而,100分未归还。 我可以查询.where(“score >= ?”, “080”) ,它确实可以根据我的需要从80-100返回所有分数,但它确实感觉非常正确。 还有其他方法我应该这样做吗? 或者,也许有人可能会准确地解释这个查询是如何工作的,所以我觉得它更好。

Rake db:放弃我的旧桌子

我的用户迁移过去看起来像这样: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :login etc 现在它看起来像这样: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :username etc 那么,为什么我会看到这个? rake db:drop rake db:create rake db:migrate rails console > User.new +—-+——-+——————+—————+——————-+————+————+ | id | login | crypted_password | password_salt | persistence_token | created_at | updated_at | […]

时间戳无法保存 – postgresql

我有以下代码片段: class Foo include DataMapper::Resource property :id, Serial property :timestamp, DateTime end 我只想将当前时间转换为ms: class Time def to_ms (self.to_f * 1000.0).to_i end end def current_time time = Time.now return time.to_ms end time = current_time # => 1352633569151 但是当我要用上面的时间戳保存Foo时,它就无法保存到数据库中而且我没有收到任何错误消息。 foo = Foo.new foo.timestamp = time foo.save 任何的想法?

无法通过Rails 5应用程序中的表单创建新记录

这个表格工作得很好,但是我已经有一段时间没用过它了,我确定我在某个地方引入了一个错误,但我无法追踪它可能是什么。 我有两个其他类似的表单,按预期提交到相同的postgres数据库。 我可以编辑现有的记录,所以看起来它只是我遇到问题的新/创建方法。 日志实际上没有显示任何错误,它只是重定向回新视图: Processing by CoffeeshopsController#new as HTML Rendering coffeeshops/new.html.erb within layouts/application Rendered users/shared/_links.html.erb (1.4ms) [cache miss] Rendered partials/_mainnav.html.erb (10.2ms) [cache miss] Rendered partials/_footer.html.erb (1.1ms) [cache miss] Rendered coffeeshops/new.html.erb within layouts/application (22.4ms) Completed 200 OK in 158ms (Views: 155.2ms | ActiveRecord: 0.0ms) Started GET “/coffeeshops/new?utf8=%E2%9C%93&authenticity_token=2A91tyxSfricbX03rLRcx9Vqm%2FuWQiZSgwwjmmScH3GrTe63RRBMTHs72%2F4cQaoXD5yC8jxY2GaRLgHvdhgCbg%3D%3D&coffeeshop%5Bname%5D=New+Coffee+Shop&coffeeshop%5Bsnippet%5D=Great+new+coffee+on+the+banks+of+the+thames&coffeeshop%5Bdesc%5D=lovely+coffee+shop+serving+Red+Brick+coffee&coffeeshop%5Barea%5D=central&coffeeshop%5Burl%5D=website.com&coffeeshop%5Bemail%5D=&coffeeshop%5Baddress%5D=&coffeeshop%5Bpostcode%5D=&coffeeshop%5Blocale%5D=central&coffeeshop%5Bphone%5D=123&coffeeshop%5Bimage_thumb_path%5D=photo.jpg&coffeeshop%5Bimage_path%5D=photo.jpg&coffeeshop%5Bbeans%5D=Red+Brick&coffeeshop%5Blong_black%5D=2.5&coffeeshop%5Btag_list%5D=tag&commit=Save+Coffeeshop” for 127.0.0.1 at 2017-06-12 17:46:34 +0100 Processing by CoffeeshopsController#new […]