0
votes
0answers
8 views

How to implement JSON in PostgreSQL with Rails 4

I am not able to find a complete and up-to-date tutorial showing how to use PostgreSQL JSON in Rails 4. I would want to know the best practice of the data structure, i.e. should I use one JSON ...
0
votes
1answer
25 views

What database should I Choose?

I am developing a Rails application with lots of data processing over huge amount of data. Client database for 2013 has 12 million records. Every 3 month I will be getting about 3 million records. I ...
0
votes
1answer
18 views

Keeping distance attribute with user model

If I have a User model, in which I have a distance attribute which I don't want to save to the database but to use it for the SQL query which calculates the distance as something that will hold the ...
0
votes
1answer
25 views

Rails- Heroku Please install the postgresql adapter: gem install activerecord-postgresql-adapter

please help me to resolve my problem I've read all topics here but still cannot understand what's going on so I run git push heroku master here is what I get rake aborted! Please install the ...
0
votes
1answer
22 views

Retrieving multiple records through has_many association

I am working on a Ruby on Rails 4 application which allows users to check off movies that they have seen. I have a page that shows a list of movies, captured through a Film model. Also, I have a ...
1
vote
1answer
33 views

Performance tuning for rails active record querying

I have rails app where I have multiple models. Such as model Input with following associations :- belongs_to :department, :class_name => 'Department' has_many :frame_inputs, class_name: ...
-1
votes
1answer
24 views

Pg:Error column does not exist

I am trying to make it so a user has_many goals, and then only let a user see their own goals. My welcome controller where the code is failing: class WelcomeController < ApplicationController ...
1
vote
1answer
34 views

Efficient way to determine if large set of rows exists in postgres

I have an idempotent background processing task that takes row of information, does some clean up and inserts into a database. My problem is that the same information may be processed more than once. ...
0
votes
2answers
22 views

postgres error for rails in ubuntu

I was having a rails application, and I want to deploy it in my new laptop ( with ruby and rails installed fresh). After installing gems and all .. when i goto my rails application folder and ruby ...
4
votes
0answers
37 views

Use Postgres Function as ActiveRecord Model

I have created a Postgres function that I am using in order to perform a complex query which joins many tables that all have to be filtered by a dynamic date field. The function works perfectly, and ...
1
vote
2answers
22 views

Can I store arrays in hstore with Rails

I want to save data like this: User.create(name:"Guy", properties:{url:["url1","url2","url3"], street_address:"asdf"}) Can I do so in Rails 4? So far, I have tried migration: add_column :users, ...
0
votes
1answer
29 views

Postgres: SELECT where a list of JOINed subtables contains specific data

In our project we have a table events each of which can have multiple dates. This means each row in dates has a event_id and a position where position (starting at 0) is unique within the same ...
0
votes
2answers
8 views

recompiling database.yml file with gemfile? ruby on rails

I'm new to Ruby on Rails and postgreSQL and had a question. Does the database.yml file get compiled when you run bundle install on a Gemfile? Initially my gemfile had sqlite3, but I changed it to pg ...
1
vote
0answers
40 views

Can access production database from Rails console but not Rails App

When I try to login to my Devise app using the rails console on my production database, I can with no trouble, however I cannot when using my Rails App. I launch my Rails Console with rails c -e ...
1
vote
0answers
17 views

Creating a custom schema.rb for secondary sql

My default models are using mysql the regular way. but i also have a postgres sql that i am using in my app, and its models look like this: class Action < ActiveRecord::Base establish_connection ...
1
vote
1answer
26 views

Postgres Query JSON Array that contains something

Postgres has this JSON datatype and I am wondering how can I query data inside a JSON array ? I am using Postgres 9.3.1 I have inserted into PUBLISHER table that has these 2 fields name: string and ...
0
votes
2answers
21 views

How to save datetime fields with validations? [Ruby / Rails 4 / Postgres]

Ok, so I need help with datetime database fields. Let's say my table is called "events" and has a datetime field named "starts_at". I have confirmed this in my schema.rb file (technically I am using ...
0
votes
3answers
43 views

Silly query on difference between nil, ' ' , '' specific to ruby language

Can anyone tell me when to use either nil, ' ', '' . Like i want to match database column which is not populated in rails/ruby. So i am not understanding which to match like .. if var == nil or if ...
0
votes
0answers
14 views

text,date datatypes in database not reflecting from front end simple_form

Below is part of my code which is not getting reflected in database. ":reason" is "text" datype and ":dated" is "date" datatype. Other columns with ":string" are getting reflected in database when ...
1
vote
4answers
31 views

Selecting rows that belong to two others using joins table

Given two models Player and Team how do I select all teams that two players specific players belong to? Example Rails models and db table setup: Rails models: class Player < ActiveRecord::Base ...
0
votes
1answer
22 views

PostgreSQL database gets dropped when I run rake db:test:prepare

In my rails 3 app, every time I run rake db:test:prepare in my local development environment, my PostgreSQL database gets dropped, and I get the following message: Chriss-MacBook-Pro-2:castingflow ...
2
votes
1answer
61 views
+50

Rails activity feed from a polymorphic following

I'm tracking the following tables: Story (id, user_id, content) Vote (id, user_id, story_id) Flag (id, user_id, story_id) etc.. with an activity table: Activity (id, user_id,action, ...
1
vote
1answer
46 views

Why isn't my PostgreSQL array index getting used (Rails 4)?

I've got a PostgreSQL array of strings as a column in a table. I created an index using the GIN method. But ANY queries won't use the index (instead, they're doing a sequential scan of the whole ...
0
votes
2answers
12 views

Returning a virtual attribute in a select query

Part of an application I'm building is an API. Recent changes mean that I need to put two different versions of the data into my json feed. I think the best way to do this is to make the necessary ...
0
votes
2answers
34 views

PostgreSQL point type in Rails migration

I want to use the point type which there's in PostgreSQL. I've done: rails g model Test point:point The resulting migration is: class CreateTests < ActiveRecord::Migration def change ...
0
votes
3answers
27 views

Using Where on association's attributes condition

I have a User model which has a languages attribute as an array (postgres) A User has_many :documents and a document belongs_to :user I want to find all document that are written by users knows ...
0
votes
2answers
30 views

ruby dropped table but can't recreate with migration

A table was dropped in a rollback migration. The migration itself was changed so that the down section dropped the table. I ran the migration that created the table again rake db:migrate:redo ...
0
votes
2answers
26 views

How to make ActiveRecord ThreadSafe

How can I make the following controller threadsafe in rails 4 with postgresql: def controller_action if Model.exists(column_name:"some_value") else @model=Model.new(column_name:"some_value") ...
1
vote
1answer
42 views

ruby migration rolled back but get error when run migration again

This is the error I get when running a migration in a RoR application: PG::Error: ERROR: column "bulk_bill" of relation "questionnaires" already exists A little background: I rolled back a ...
1
vote
0answers
19 views

Missing logs from heroku pgbackups addon

I have deployed Rails app to Heroku. App uses PostgreSQL for data management. It works fine locally. I am searching for a way to push my local PostgreSQL database to the Heroku database. heroku ...
0
votes
1answer
28 views

Add primary key to an existing field in Rails

Once upon a time I made a join table with no id: create_table :products_stores, id: false do |t| t.belongs_to :app t.belongs_to :product end I later wanted to use it for the position of each ...
0
votes
1answer
29 views

Postgres update where id in (list) not updating the last entry

I am building a ruby on rails backend to support an ios and android application. A piece of the code was supposed to handle chat message being pushed via push notification. For some reason when ...
1
vote
1answer
17 views

Rails+PostgreSQL: Does setting column default values hurt in terms of DB space?

This is a quick question. I was curious as to whether setting the default value for a column in Rails+PostgreSQL costs additional space (versus leaving the default as nil). I am also curious if that ...
0
votes
1answer
22 views

PG::ConnectionBad FATAL: role “BetBook3” is not permitted to log in

I am getting the above error when entering localhost:3000 into the browser. I have attempted to restart the browser but this did not work. This is the stack trace from the server console in ...
0
votes
1answer
19 views

Limit all postgresql with rails must be integer

I'm just trying out some stuff and I found something interesting, when I try to pass a string argument to the limit method I get an error. Here is an example : User.where('id > ...
0
votes
3answers
26 views

Find records included in range of numbers (min - max)

Course.rb min_age: integer max_age: integer Student age comes from params[:age] - for example 15, that means student is 15 years old and he looks for courses that will cover his age: I have ...
1
vote
2answers
40 views

paginating over big number of records

I've got a big number of records and I display only part using a pagination. Which is ok. Since I have many pages I'm obtaining count on each page, is there a tecnique to avoid this? I've got a redis ...
0
votes
1answer
41 views

Create or update multiple records at once?

I have the following code that takes results, groups them by date and creates a customer count for that date, and then inserts it in to a Calculation table: customers.group_by { |c| Date.parse ...
0
votes
0answers
14 views

How do index documents imported in bulk with Searchkick

I'm using the gem activerecord-import to bulk-load data into a Postgres database, which is indexed in elasticsearch using the searchkick library. How can I can I cause ElasticSearch to index the newly ...
0
votes
0answers
30 views

Rails 4 group belongs_to multiple columns and average

I am working on a project that will allow users to search through averages of course evaluations (similar to ratemyprofessor). Using Rails 4 & postgresql, and am running into issues with ...
0
votes
2answers
22 views

Dropping column from DB

When I created a column for my Rails model for attachments, I used: def self.up change_table :updates do |t| t.attachment :image end end def self.down drop_attached_file :updates, :image ...
1
vote
1answer
45 views

Simple postgresql Insert/Update queries taking *seconds* to respond every 5-7 minutes

I have a Ruby on Rails app that is using a Postgresql database. I've noticed that my database performance has huge spikes every 5-7 minutes. I'm seeing 1+ second response times for simple queries ...
0
votes
1answer
14 views

Return value from ActiveRecord::Base.connection

I am using raw SQL via Delayed Job in a Rails application. I realise there are Rails methods for doing this, but bear with me. The SQL is updating fine, but I would like to review the return value. I ...
0
votes
3answers
44 views

How to remove duplicates in postgresql / Rails joins result set

I have below query: SELECT "users".* FROM "users" INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON ...
1
vote
1answer
13 views

permission denied to create extension “uuid-ossp”

I'm building a Rails project on postgresql, but when I rake db:migrate I get the following error: permission denied to create extension "uuid-ossp" Here's how my database.yml looks like: ...
0
votes
2answers
30 views

Heroku pgbackups restore resource not found

I am currently trying to migrate a database on one app to another in heroku by following this: https://devcenter.heroku.com/articles/migrate-heroku-postgres-with-pgbackups After running: heroku ...
0
votes
1answer
20 views

Active record multiple joins returning wrong values and duplicates Rails

I've got below query on my custom class in Rails 4: User.joins(:roles).joins(:events).joins(:booths).group("users.id, roles.id") This however returns multiple duplicates of wrong users. I want to ...
0
votes
1answer
16 views

Where clause on model associations

I have below where clause: users.joins(:role).where("roles like :search OR email like :search OR first_name like :search OR last_name like :search", search: "%#{params[:sSearch]}%") I want ...
0
votes
0answers
32 views

Travis ci, Rails and Postgresql - ERROR type hstore does not exist

I'm getting: PG::UndefinedObject: ERROR: type "hstore" does not exist LINE 1: ...arying(255), "finish" timestamp, "widget_locations" hstore) Below is my Travis config file: language: ruby rvm: ...
1
vote
1answer
18 views

How to model table with items which have multiple subcategories?

I need some advice. I am pretty new in modeling database so I was wondering what would be the most convenient way to model database which would make my life easier. I have one Car item which can have ...

15 30 50 per page