0
votes
2answers
30 views

Select last unique polymorphic objects ordered by created at in Rails

I'm trying to get unique polymorphic objects by the value of one of the columns. I'm using Postgres. The object has the following properties: id, available_type, available_id, value, created_at, ...
0
votes
1answer
18 views

Rails query interface: selecting rows in database where any of the JSON array's values match a certain criteria

Database info: Database: PostgresSQL Table name: publishing_rules Column name: menu_items Column format: JSON Example column value: {"items":[{"id":1,"title":"dfgdfg"},{"id":2,"title":"sdf"}]} I ...
0
votes
1answer
40 views

Ruby Grape POSTGRESQL stored procedure

Trying to execute a POSTGRESQL stored procedure/function in Ruby Grape API Package. I have the function getactivesites() in my server which returns the site name. server code: BEGIN RETURN ...
0
votes
0answers
24 views

Optimize creation of a nested hash from table

I have about 12,000,000 products in a table and looking to build a nested hash in Rails. I output this as JSON to clients. The table only has a few columns: date_time, country, category1 through 3 ...
-2
votes
1answer
39 views

Can a Rails attribute be an array?

I recently learned about the json datatype in Rails 5, which allows you to store a hash in a PostgreSQL database. For some reason I can't find a full list of Rails 5 datatypes. Is there any sort of ...
0
votes
1answer
44 views

ActiveRecord scope based on hour

iteration <% @challenges.with_exact.each do |challenge| %> etc... <% end %> model scope attempts scope :with_exact, -> { where("exact == ?", Time.zone.now.hour) } # Error: PG::...
0
votes
2answers
26 views

ActiveModel::MissingAttributeError: can't write unknown attribute `attendee_id`

I am trying to create an association between a User model and an Attendance model in which an attendee_id references a user. The association is a many to many relationship between users and concerts. ...
1
vote
2answers
40 views

Leaflet data format

Making a map using Leaflet via Ruby on Rails var map = L.map('map').setView([34.05, -118.25], 13); // gon is a gem which allows reading of variables defined in the Rails controller var ...
1
vote
1answer
32 views

Limit number of items from a sub-category in a list of products on category page?

In my rails 4.2 application, I am showing a list of items in a page belonging to several different subcategories which belong a category. I'm also showing list items on sub category's page as well. On ...
1
vote
2answers
28 views

How do i connect my postgres db in heroku?

I am learning rack and I built a test todo app. My test app uses postgres db. I am trying to deploy my app to heroku free account. Currenlty I am trying to connect to postgres using this DB = PG....
1
vote
0answers
36 views

How to sanitize ruby-pg data before select?

I have the following db interogation in ruby-pg: a = product[:id].in(Spree::Product.joins(:taxons).where("spree_products_taxons.taxon_id in (params)").map(&:id)) How do I sanitize the params ...
2
votes
1answer
59 views

Why ruby sort array of strings differently than sql order (postgres)?

When the code would tell better than words: [4] pry> Models::Company.order(:name).select_map(:name) => ["Dekker, Jacobs and Bosch", "Koster en Zonen", "Peters-Koster", "Peters, Vries and Smits",...
0
votes
0answers
39 views

How to define the database for ActiveRecord migrations when database is hosted

I am using a non-Rails Active Record migration tool, and a hosted Postgres database from Heroku. My dev environment is on Digital Ocean. The production code will be on Heroku. According to the docs,...
2
votes
1answer
23 views

Handle connection breakages in rails

I have a module written in ruby which connects to a postgres table and then applies some logic and code. Below is a sample code: module SampleModuleHelper def self.traverse_database ...
0
votes
1answer
19 views

Ruby & Postgresql LIKE for both string and decimal

I have a search query that worked in sqllite, but when I migrated to postgres it doesn't work anymore. I can understand the error, which is below, just not sure how to fix it.. This is the error: ...
0
votes
1answer
51 views

Is there a parameterize function in PostgreSQL like in Ruby?

In Ruby, there's a very useful function on string objects which will take a string and parameterize the characters in that string so that can be used in a URL. i.e.: 2.2.2 :001 > "Rising Star"....
0
votes
1answer
21 views

Displaying random products in ruby on rails app

In a app I'm building, a customer selects a product and in the products/show.html.erb he is supposed to be able to see related products in a below div. category.rb and product.rb are related: ...
0
votes
1answer
23 views

Data not uploading in my postgresql database of my model (Content)

I want to know what I'm doing wrong as my title and body that I specify on rails console are not uploading directly to my postgresql database. My first Model (category.rb) file: class Category < ...
0
votes
3answers
33 views

How to Rescue ActiveRecord::StatementInvalid Error

Does anyone know how to rescue this ActiveRecord::StatementInvalid error in rails? The console displays "PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer...". I've tried ...
0
votes
2answers
45 views

In rails, given an array of Point objects, how do I sum the point values for each player?

We're using postgres for this project. The goal is to get a hash which pairs each player with the sum of their point values. I have an array of Point objects which looks something like this: (Note: ...
0
votes
2answers
118 views

Simple Rails App: Error Cannot visit Integer

I am trying to build a simple Rails app. Rails v3.2.22.5 (it is a requirement). I am running it with PostgreSQL. When I start the server however I get the following error when I try to read a simple ...
0
votes
2answers
22 views

How to convert value hashes from a stored procedure into an array of Sequel model instances or dataset

A stored procedure returns an array of rows (SETOF) from a table called ACCOUNTS with its associated Sequel model Account: [1] pry(#<Psql::CalculateMasterBalancesTest>)> DB.select(Sequel.lit(...
0
votes
1answer
24 views

How to print postgres “raise notice” output from Sequel?

Raise notice is typically used to debug PSQL scripts in postgres (link). The docs say that there's some kind of support for printing notices when using the pg gem, but there's no info on how to use ...
-6
votes
2answers
84 views

Regular expression to split ruby strings into multiple hashes

I have a string like this one in a jsonb column in my Postgresql database: "{\"monday\"=>\"{:start_time=>9.0, :end_time=>10.5}\"},{\"tuesday\"=>\"{:start_time=>8.5, :end_time=>10.0}\...
0
votes
0answers
59 views

datetime saved in database but when i want to call the datetime it is a nil value

I have a datetime, called due_date, that gets saved in agreement table. When i want to display the datetime, it just gives me nil, however Im looking at my db row and its clearly not nil. must be some ...
0
votes
0answers
14 views

Overriding initialize_type_map for Rails 4's ActiveRecord's PostgreSQL adapter

We have a database that is now in the tens of thousands of schemas. The more schemas that we have, the greater the app memory consumption and the boot time is. We've been running a few tests and we'...
0
votes
0answers
28 views

How to Get Sum of Field Totals, Separated by Field Name, and Grouped by Month in Rails JSON Hash

I want the sum of modality totals, separated by modality, grouped by every month and outputted as a JSON Hash. Exams model column: from_date Modalities model columns: modality_name, total, exam_id ...
0
votes
0answers
37 views

Error Generating Fixtures. Rails was not able to disable referential integrity

I understand that rails is supposed to disable referential integrity when generating the fixtures. So after a quick Google search, i figured out that the solution to the error following error is to ...
0
votes
2answers
36 views

Sort by association of association

Order belongs_to :delivery_timeslot DeliveryTimeslot has_many :orders DeliveryTimeslot belongs_to :timeslot Timeslot has_many :delivery_timeslots I want to sort by id of timeslots: Order.includes(...
0
votes
0answers
31 views

Rails Backup gem postgres password issue

On db configuration the db has a password, everything works fine but when i run the command backup perform -t db_backup --config-file /data/Backup/config.rb the backup just shows: someone have any ...
0
votes
0answers
19 views

Rails how to set the Backup gem to another dir?

After install and generate the Backup the Backup folder with the model, config, and logs goes to user home directory, so, how to create the Backup to another dir? for exemple i would like to create ...
1
vote
0answers
35 views

ruby on rails' alphabetical order method doesn't place word boundary before “a”? [duplicate]

I think this has something to do with Postgresql, because in a local sqlite3 database, I don't see the behavior. I'm creating a Ruby on Rails 5 app with a postgresql DB. I'm using c9.io though, à la ...
0
votes
3answers
40 views

Rails db:create failing with Postgres, claiming role doesn't exist when it does

I've seen a mountain of questions related to this, but up to now none of the solutions that have worked for others have worked for myself. presently my attempts to run 'rails db:create' are getting ...
0
votes
1answer
20 views

When mapping on an ActiveRecord query, my date object stored in the db is converted to a string

I'm trying to use ActiveRecord's date.beginning_of_day but when I'm mapping the query I want to use that method for, the Date obj is being converted to a string. Here's the code snippet: ... array = ...
0
votes
0answers
74 views

Can't install PG gem inside Ubuntu 16.04 Docker Image

I had a problem similar to this one, on my Docker host computer. I was able to fix it by installing libpq-dev on the host machine, as suggested. But when I create a Docker image using ubuntu:16.04 as ...
0
votes
0answers
19 views

Running a ruby sinatra postgreSQL error

I have been trying to run my ruby app that previously was run on my MACbook. Currently, I am using a Windows OS and bash. PostgreSQL is installed. So are Sinatra and Ruby of course. Every single time ...
0
votes
1answer
29 views

Can't connect to postgres with 'pg' gem?

I have the following code where I'm trying to test a connection to postgres: require 'pg' conn = PGconn.connect("localhost", 5432, '', '', "puppetdb", "puppetdb", "puppetbdb") res = conn.exec('...
0
votes
1answer
37 views

Rails spec using Postgres test environment, test tables don't restart id increment?

Just switched from from sqlite for testing to pg. I noticed that, while the test table clears out just fine, the IDs don't restart to 1. So in other words, given the test: describe "" do before do ...
0
votes
1answer
48 views

ActiveRecord, order objects based on JSON datatype

Just learning about JSON datatypes, wondering if there's a wonderful shortcut Rails has created to do some ordering. Suppose I have object_a.payload = { "category_1" => 2, "category_2" => 1 } ...
1
vote
1answer
63 views

Rails 5 - How to have shared data across multiple tenants in apartment gem?

In rails 5, I am working on multi-tenancy feature using apartment gem. I have to show the common dropdown data to all the tenants but it is not working. Eg: I have cities list. Two tenants are ...
0
votes
1answer
24 views

How to add a down block for Sequel add_unique_constraint migration

I have a Sequel migration in PostgreSQL, which works up, but not down: Sequel.migration do change do alter_table(:files) do add_unique_constraint [:name, :folder] end end end When ...
0
votes
1answer
56 views

How can write I sql query with rails commands

My sql command like this. Im trying to relation with two tables. I need the write that query to ruby command with rails helpers. select *, (select branch_id from branches_course_contents ...
2
votes
1answer
60 views

Rails 5. Update association with exception handling

I have a one-to-many relationship between the classes P(parent) and C(childs). Table C has a unique composite index {p_id, somerow}. Having 2 objects of class P (p1 and p2), I want to combine them ...
0
votes
1answer
36 views

deploying rails app first time to server capistrano

Im trying to deploy to a server with ubuntu 16.0.4 with nginx, passenger and postresql. And now when I'm deploying for the first time it all works fin until capistrano runs rake db:migrate. ...
1
vote
1answer
36 views

Picking objects with ranges using input number in Rails

I have objects that have a min/max age range on them: name: "Event 1" type: Package # inheritance min_age: 1 max_age: 8 category_id: 2 # Birthday I would like to select and return these objects ...
0
votes
0answers
12 views

If we click on 'Get Desc' button , it should give the description column of 'programs' table and all the table should be disappear

Here, I created one table in ruby's socket programing. I have taken 2 columns from postgresql. In the 3rd column, I need to create buttons, which we click, then the same db tables's 3rd column, which ...
1
vote
1answer
40 views

Rails 5.0.1, postgresql - aliased foreign keys and aliased tables with includes fails

tl;dr: Database obfuscation of all tables and columns (including foreign keys) is causing a problem in obtaining a result in eager loading of associated models from postresql database using all ...
0
votes
0answers
27 views

Timestamp is rendered inconsistently on Heroku dyno

I am having a rough time getting a Rails 5 view (hosted on a Heroku dyno) to render a consistent timestamp value. The Heroku support team can't figure out the issue. 1) I visit the specific view (an ...
1
vote
2answers
41 views

pg gem install fails

Centos 6.9 (similar to question: Can't find the PostgreSQL client library (libpq) but that one is on MacOS not Centos, so those solutions did not work ruby 2.1.8 (tried 2.2) rails 4.2.6 (tried 5....
1
vote
1answer
71 views

Programmatically composing INTERSECT and UNION queries with Arel or ActiveRecord

I need to write a query, using Arel or ActiveRecord, in Rails 5, using intersections and unions. Every answer on SO that I've found so far about this generally seems to involve transforming the ...