Tagged Questions
0
votes
1answer
13 views
What's the best way to track versions on a specific column of a table?
I have a webapp that for these purposes can be considered a collaborative blog or wiki. People view a set of documents and edit then republish them, and we need to keep track of a revision history on ...
0
votes
1answer
21 views
How do I delete all records related another record and greater than a certain threshold efficiently?
I'm trying to delete all notifications older than the first 99 for every user. Here's what I'm currently doing in rails:
User.all.each do |u|
u.notifications.order('created_at ...
0
votes
1answer
14 views
ActiveRecord::StatementInvalid in Home#index
I'm trying to open a local project in ruby using some old files (of another project) and I'm getting this error. My problem is that I don't have that table in my db.
This is the error:
...
0
votes
3answers
21 views
How to add OR to a where statement when setting Rails instance variable?
How would I add "OR" to this where statement when setting my instance variable in a Rails controller?
@activities = PublicActivity::Activity.order("created_at DESC").where(owner_type: "User", ...
0
votes
0answers
17 views
Heruku App Push SQLite error
I have configured PostgreSQL on my development.
Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.2'
gem 'sass-rails', '4.0.1'
gem 'coffee-rails', '4.0.1'
gem ...
0
votes
0answers
24 views
Rails 4 Arrays working fine on heroku not on local
I have installed postgres on the development environment and still cant get the arrays to work on it. It keeps appearing as "{\"\",1,12,13}" as opposed to being [1,12,13] although the exact same ...
0
votes
1answer
18 views
Rails/Heroku - Dropped table and can't get it back
I have screwed up my migrations/schema/db to the point that I can't seem to figure this out.
Locally, I had a comments table. I needed to restructure this table completely, so I opened up my initial ...
2
votes
2answers
36 views
Get the latest records of a has_many relation
I'm trying to create a query in postgres using (rails) activerecord, but can't seem to solve it.
A Company has many pages, and I'm trying to get the latest page of all companies.
I tried
...
0
votes
1answer
44 views
Rails limit each set of group using activerecord query
My question is somewhat similar to this - Active Record LIMIT within GROUP_BY
I want to limit the ActiveSupport::OrderedHash to a specific count(100) for each site.
The limit can be anything like ...
0
votes
2answers
42 views
Manually deleted a row in postgresql and now ActiveRecord is breaking
My Rails app is using ActiveRecord backed by Postgres. I went into the database through psql and deleted a row from one of the tables. In hindsight this was a terrible decision as it is causing parts ...
0
votes
3answers
44 views
Heroku : Postgres - could not connect to server: Connection refused
I am desperately trying to push my app to heroku but it fails with this error message.
It works on my local machine but I can't even push it to heroku.
I've been trying to make this work several days, ...
0
votes
2answers
29 views
ActiveRecord multiple joins and count [on hold]
I have the following models:
User:
has_one :extraction
Extraction:
belongs_to: user
has_many :pages
Pages:
belongs_to :extraction
Now I want to return all the users and each of the user's ...
0
votes
1answer
28 views
Convert a complex PostgreSQL query to Ruby
I'm new here and have some difficult to convert a complex Postgres query to Ruby. Here is the query:
SELECT date_part('year', p.created_at) AS anio,
date_part('month'::text, p.created_at) AS mes,
...
0
votes
1answer
24 views
How to enable rails and postgresql on start up in centos
I have a server with centos running rails application each time when I reboot my system I have doing following tasks manually. How to enable all the following tasks in start up
To stop and start my ...
0
votes
1answer
21 views
Rails 4 Heroku postgreSQL Error
I'm having trouble changing an existing app with SQLite3 to postgreSQL. I'm following this tutorial to convert SQLite3 to postgreSQL and deploy it to heroku: ...
0
votes
1answer
20 views
not able to reset heroku database
I recently upgraded from a hobby-dev plan to a hobby-basic plan but something really weird is happening. I have a ton of data and my site works just fine but when I do heroku pg:info, it says I have 0 ...
0
votes
2answers
20 views
tsvector_update_trigger can't find tsvector column
I'm working on a pretty simple blog in Ruby on Rails and is currently implementing the search functionality using pg_search for PostgreSQL full text search. Unfortunately, I'm having a problem with (I ...
0
votes
1answer
16 views
Setup Heroku Database for the first time
I am using postgresql and have been operating under my local dev environment. I deployed my app to Heroku, and now I need to setup heroku to use a database just like I have locally.
Locally, I would ...
0
votes
0answers
20 views
ActiveRecord::StatementInvalid: PG InFailedSqlTransaction
I am trying to create an ActiveRecord Object.But I'm getting this error while creating it.
(0.1ms) ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction is ...
0
votes
2answers
49 views
Rails 4 - how to use sqlite3 in development and PostgreSQL in production w/Heroku
I am trying to deploy to Heroku but can't because the default sqlite3 server is still in place.
Detected sqlite3 gem which is not supported on Heroku.
...
0
votes
0answers
19 views
Find the sum of related relations of a Model and all of its children
I have 2 tables: transactions and categories, such as category has_many transactions and transaction belongs_to category
Besides that, in category model I have the following:
belongs_to :parent, ...
0
votes
1answer
18 views
Convert SQLite String to PostgreSQL
I recently converted a string to a decimal in Rails using migrate and this works fine locally. I then pushed my application to heroku and got the following error:
Running `rake db:migrate` attached ...
0
votes
1answer
25 views
Which route should be used?
I am trying to figure out what route I need to create to get something like the below to work. Thanks in advance!
Dashboard HTML:
%td= button_to "Join", { action: "join_group", id: group.id }, ...
0
votes
3answers
37 views
why is rails telling me to run rake db:migrate?
Hello I am new to rails.
I am working with an existing postgres db. I would like to create CRUD for all of the tables.
I've started with:
rails g scaffold firstTableName
Then I start rails:
rails s
...
0
votes
0answers
21 views
Easily generate SQL script for an Array of objects - Rails
I made a Rake Task to parse information from some websites (using Nokogiri gem) and save everything to a .json file. To do this, I store all objects inside and array and before the rake task ends, I ...
2
votes
3answers
29 views
Using a join table to exclude records from appearing in a random query
I'm working on a rails app where a user is presented with a random question from a user selected category. If the user has answered the question, I would like for it to never be presented to the user ...
0
votes
4answers
30 views
What is the best way to order by parent and child's created_at?
Suppose I have a parent Comment that has many Replies.
class Comment < ActiveRecord::Base
has_many :replies
class Reply < ActiveRecord::Base
belongs_to :topic
I would like to order ...
1
vote
1answer
41 views
where not in fails if converting datetime columns to date (rails)
When I try searching for records that weren't created_on particular days, the conversion from datetime to date fails in the query
>> some_days = [Date.parse("2013-12-25"), ...
0
votes
2answers
22 views
Writing postgresql method on model to get datetime entries by day of week
I have a column in one of my model's (team_opps) that is a datetime column called start_date. I recently migrated my db from sqlite3 to postgresql and this blew up the method.
Here is the method ...
2
votes
2answers
43 views
How do you combine multiple Rails SQL queries into a single query in rails?
In my rails code, I need to run a query on a table based on a combination of the date of the records and votes that the record has received. I accomplish it like the following in rails:
if ...
0
votes
1answer
41 views
Why am I getting these PostgreSQL errors since upgrading to Rails 4?
Before upgrading to Ruby 2 and Rails 4, my Rspec test suite was passing completely.
Since then, I have:
Upgraded from Ruby 1.9.2 to Ruby 2.0.0
Upgraded from Rails 3.2.11 to
Rails 4.0.2 Upgraded a ...
0
votes
1answer
41 views
Errors when connecting to local Postgres.app from Navicat or Induction
Ok, so I have Postgres.app on my mac.
It's running locally insofar as I know. (the little elephant icon in top bar)
Created a very basic rails application, and it worked fine, ie, it showed up in ...
0
votes
0answers
26 views
Repeated query on related table are very slow. How to adjust schema to be efficient?
I have two related tables on in a postgres DB. Let's say the first table is Products and the second is Transactions. I have a search feature that queries Products based on specific attributes, some ...
0
votes
0answers
27 views
Rails: where all children date matches condition
I have the following models:
class Tour < ActiveRecord::Base
has_many :sessions
end
class Session < ActiveRecord::Base
belongs_to :tour
end
I need to get all tour whom all sessions are ...
1
vote
2answers
29 views
Rails delete the parent model, but still access the children
I have customers and invoices. The users can delete customers, but not invoices.
The problem is when a customer is deleted I can no longer do
invoice.customer.name
Because customer is nil.
I have ...
0
votes
1answer
42 views
Stuck trying to build Pg gem on OS X 10.8.5
Result of 'bundle install' in Terminal:
An error occurred while installing pg (0.16.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.16.0'` succeeds before bundling.
Result of ...
1
vote
2answers
38 views
How to get this postgres group by date count include days with 0
I have this Postgres query to select all users from the last 30 days and group by count.
@users = User.where('created_at >= ?', last_30_day).count(:order => 'DATE(created_at) ASC', :group => ...
1
vote
2answers
26 views
Checkboxes with join table and rails
I have a Users table, Activities table, and UserActvities join table. Activities resources are nested under User resources. I want to allow a user to select multiple activities at once so that they ...
0
votes
2answers
50 views
PG::SyntaxError: ERROR: At Production Mode in Rails
I am building a web application for which crashes when it is running on production mode @ Heroku and trying to execute the following query whereas in development mode everything is running smoothly.
...
4
votes
2answers
124 views
What database to use for 15M records and a fast search index
So this is something I have been wondering about after working on a project for about nine months.
We have a postgres database and are using sunspot on top of solr in a rails app.
I was not here ...
1
vote
0answers
27 views
Enabling the hstore extension in Amazon RDS from Rails 4
I have a Rails 4 application that uses ActiveRecord to interact with a PostgreSQL 9.3 database. The application makes use of the hstore extension in PostgreSQL for storing key-value pairs in a single ...
0
votes
2answers
133 views
Avoid SQL`s JOIN when using ActiveRecord`s includes method?
I've this ruby code which cause postgresql to raise column "urls.id" must appear in the GROUP BY.
Song.
joins(:artist).
references(:artist).
where("artists.active = ?", true).
...
1
vote
1answer
33 views
ActiveRecord::Base SQL result object types different in MySQL and PostgreSQL
Am I missing something? Same console, same codebase, different database connections. Result: different object types returned. If MySQL is used, we get an array of arrays, if PostgreSQL is used, we ...
2
votes
1answer
37 views
Rails Postgresql - synonym dictionary somewhat not updating
I have a Rails4 app with Postgresql(PG_search) on a MAC. I created the synonym dictionary through rails migration. The synonym dictionary is somewhat working. Setup below
Migrations
CREATE TEXT ...
0
votes
1answer
18 views
dependent:destroy throwing error with postgresql
I'm new to Postgres and I'm getting this error when testing the destroy action for a blog-type application. It seems like the problem is that works, rather than work, is being called for a given ...
0
votes
0answers
35 views
uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn (NameError) on
I am getting this error when running guard in my rails 4 app. At first I thought it was a problem coming from the rolify gem because removing it from the user model removed the error temporarily but ...
2
votes
1answer
50 views
Rails migration generates default timestamps (created_at, updated_at) as NULLABLE
Some time ago we upgraded our application to Rails 4 and switched to JRuby.
Before that change migrations created the default timestamps as NOT NULL.
After that change the NOT NULL is missing.
We ...
0
votes
1answer
36 views
GroupingError: ERROR: column must appear in the GROUP BY clause or be used in an aggregate function
I have code in my controller that is ranking albums by the highest average review rating (used code from this solution How to display highest rated albums through a has_many reviews relationship):
...
0
votes
1answer
17 views
Rails: Batch Subscribe users to MailChimp API on Heroku running into timeout issues
Here is my code
users = User.all
# Latency issues with connecting with Heroku and MC
Gibbon::API.timeout = 120
gb = Gibbon::API.new
batch = []
users.each do |user|
batch << ...
0
votes
1answer
33 views
I can not create PostgreSQL database via prompt with Ruby on Rails
Hello Guys I'm trying to study Ruby On Rails but I can not continue reading a book written by
Brazilian author.
I was going step by step (A, B, C, D, see below) and PROPERLY INSTALLED POSTGRESQL
A) ...