Tagged Questions
1
vote
2answers
44 views
Why is my foreign key association not yielding results?
I have two models in my rails app, Appointment and Policy. My Appointment model has_many :policies, class_name: "Policy", foreign_key: 'writing_code' and my Policy model belongs_to :appointment. The ...
0
votes
2answers
38 views
changing database from PostgreSQL to MySQL in a Ruby on Rails app
In my current application i am using PostgreSQL Data base,
but I want to change the PostgreSQL database into MYSQL DB.
if it's impossible ?
-1
votes
0answers
17 views
A few postgres 9.3 tables' Index not created in Rails 3.2
A few tables' indexes were not created at all after rake db:migrate in rails 3.2 app. Those tables are even missing the primary key. What we did was manually creating all the indexes.
Not sure if ...
0
votes
1answer
15 views
Is this model method locking up my PostgreSQL database?
My application is crashing really, really hard, and it appears to be related to the database. The application deals with lots and lots of data, and hundreds of simultaneous users. In an effort to ...
0
votes
2answers
41 views
Find record whose field 'name' not contained within any other record
I have a model Foo with a String bar and a String name. Some records' bar contain the name of other records in them. This is intentional.
I want to find the "root Foo" records - that is, the ones ...
0
votes
1answer
27 views
Delete everything but the first n items (Rails, PGSQL)
Assume I have a table called post, that belongs to user.
class Post < ActiveRecord::Base
belongs_to :user
end
class User < activeRecord::Base
has_many :posts
end
Such that the posts ...
0
votes
1answer
47 views
Find Record from Array Field In PG
TableName : NameYear
This is my Table
ID name min_max_year
1 xyz [1970,1971...2014]
2 abc [1980,1981...2014]
2 pqr [2000,2001...2014]
Now I want to find records that MinMaxYear include 1980.
...
6
votes
2answers
171 views
How do I make Rails use SSL to connect to PostgreSQL?
When I try to connect to the remote PostgreSQL database with a Rails 3.2 project I get this error:
FATAL: no pg_hba.conf entry for host "10.0.0.3", user "projectx", database "projectx", SSL off
My ...
1
vote
1answer
42 views
“ null value in column ”version“ violates not-null” on db:migrate
I am trying to rebuild my development database from bare metal and am getting a strange error that I've not seen before. I cant seem to track down the cause. Here are the commands I am running and ...
0
votes
0answers
23 views
Rails dependency hell with postgis and postgres
trying to setup a development environment for a new project I was brought on to. They have postgres and postgis.
I am able to connect to my development and production databases.
When i run the ...
1
vote
1answer
36 views
MySQL to Postgres group_by error
The following query works fine in MySQL (which is generated by rails):
SELECT
sum(up_votes) total_up_votes
FROM
"answers"
WHERE
"answers"."user_id" = 100
ORDER BY
"answers"."id" ASC
...
2
votes
2answers
42 views
Setting boolean values in the DB
The way that boolean values are stored varies from database to database. Some use 1 and 0 integer values to represent true and false, respectively. Others use characters such as T and F.
How do I ...
1
vote
4answers
76 views
Why is it best to store a telephone number as a string vs. integer?
As the question states, why is it considered best practice to store telephone numbers as strings rather than integers in the telephone_number column?
Not sure I understand the rationale for this. ...
1
vote
1answer
23 views
Understanding random ordering in Rails + postgresql
So, I'd like to do some random ordering when displaying data the code I have at this point is:
Timsheet.limit(1).offset(RANDOM(Timesheet.count)).first
I know that postgresql's (RANDOM) syntax is ...
1
vote
1answer
107 views
Failure to Create Table on Heroku — Migration works locally but fails on Heroku
I'm working on a Rails 3 app and am trying to run a migration. I am trying to create a table called Songs and I was able to successfully create the table and migrate locally. However, when I push the ...
3
votes
1answer
28 views
Multiple Devise Users with different dashboards
I have 2 types of users , and generated devise models and views for them . Had to do this basically because using roles was out of question here . Both Users are different and will have different ...
1
vote
1answer
83 views
Heroku Rails App terminates immediately (SIGTERM)
I'm trying to simply get the basic Rails application going, just initializing an empty/default project and put it on Heroku.
However, no matter what I try, I can't seem to get the default "Welcome ...
1
vote
1answer
97 views
Distinct on Postgresql JSON data column
Trying to do distinct on a mode with rails.
2.1.1 :450 > u.profiles.select("profiles.*").distinct
Profile Load (0.9ms) SELECT DISTINCT profiles.* FROM "profiles" INNER JOIN ...
1
vote
1answer
34 views
Switched MySQL to Postgres: “column must appear in the GROUP BY clause or be used in an aggregate function”
Switching a rails app from MySQL to Postgres gives the following error:
ERROR: column "contacts.id" must appear in the GROUP BY clause or be used in an aggregate function
Here is the scope in ...
0
votes
1answer
31 views
Ordering with Rails query with Hstore
I have a model Post
#<Post id: 121978, created_at: "2014-05-02 18:11:15", updated_at: "2014-05-02 18:11:15", data: {"hi"=>"1", "hello"=>"9999"}, review_id: nil>
And I'd like to sort ...
1
vote
2answers
103 views
what are the main differences between mysql and postgres? [closed]
I want to create a new rails application. For that i am confused between mysql and postgres. Please suggest me which one is the best and their difference. This question may be wrong, if its wrong ...
0
votes
2answers
32 views
ActiveRecord except one with specific id
I have this search query:
@ebm_entry = @patient.ebm_entries.find(params[:id])
@ebm_entries = @patient.ebm_entries.where("created_at::date = ?", @ebm_entry.created_at.to_date)
@ebm.entry returns ...
0
votes
1answer
50 views
time is not saved in UTC time
Using Rails 3 and PostgreSQL 8, I have a fuel_date column with data type "timestamp without time zone". A user selects a date and time from dropdown menu in their local time and when it's submitted to ...
1
vote
2answers
180 views
Use associated values on has_many through relations to filter a table in active admin (Rails 4/Active Admin)
I have a basic has_many through models where a customer can have multiple games:
The Customer model belongs to a Partner and consequently has a partner_id column,
same for the game model that belongs ...
1
vote
0answers
38 views
Rails installation on hostmonster bundle install fails
So I had a rails app up and working on my hostmonster account just fine. I then updated a few things in my dev environment / pushed them up to github / pulled them back down on my production ...
1
vote
0answers
43 views
bumping the character limit on a varchar field which is used in a view
I have the following Rails Migration:
class ChangeCommentLength < ActiveRecord::Migration
def up
change_column :videos, :comment, :string, limit: 500
end
def down
...
0
votes
0answers
22 views
Search for containing words with word boundaries in Rails+Postgres
I want to search the database for "containing words" -
when I have the entries
afoo bar
afoobar
afoo barbar
foo bar
searching for "green foo bar", it should only return the last entry. So it's a ...
0
votes
2answers
75 views
How to select rows with max(:created_at (Rails 3, PostgreSQL)
Want to get (this){example ⬇} data from db.
Have data like this :
=> #<Item id: 2330, asin: “7701C6RHIY", domain: "com”, title: “badfsd”, created_at: "2014-04-04 01:42:28">
(this) => ...
1
vote
3answers
41 views
How to delete data from DB with the same dates except the biggest date. Rails 3
I have date like:
=> #<Item id: 8749, asin: "B000V2ACH8", created_at: "2014-03-24 00:15:24">
=> #<Item id: 8750, asin: "B000V2ACH8", created_at: "2014-03-24 14:35:24">
=> ...
0
votes
1answer
30 views
Multiple PSQL gems causing problems
I have a rails 3.2.8 site that was configured to use Postgres.App. The gem it was using was pg (0.12.2) It was working fine. I wanted to build another app and so set everything up as with the other ...
1
vote
1answer
113 views
rails gem Make_flaggable doesn't save to db
Just went through the tutorial, set everything up. When I ran the command line test it seems that methods are picking up the right data, but not saving them into db.
irb(main):009:0> u.flag(s, ...
4
votes
1answer
139 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
0answers
25 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 ...
0
votes
1answer
91 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 ...
0
votes
1answer
195 views
Heroku pg_dump version mismatch
I am stuck with an error trying to push a database to heroku
pg_dump: server version: 9.3.3; pg_dump version: 9.1.9
pg_dump: aborting because of server version mismatch
pg_dump: *** aborted because ...
1
vote
2answers
273 views
Filter on :string not working on Active Admin (Rails 3.2/postgresql)
I am using Active Admin on my Daily Deal app.
I have run across a very specific issue: when I launch a search on the filter sidebar on a field that was defined as filter :as =>:string, I get this ...
1
vote
2answers
78 views
How to efficiently execute multiple SQL queries with the same WHERE clause
I'd like to do multiple SQL queries that share the same WHERE clause. My queries all involve counting the number of entries in various groups. At the moment I'm executing each query separately, which ...
-1
votes
1answer
53 views
How do I calculate two dates and return a numeric value, enabled filter by that value?
For example:
Product.select("((100*(? - fabricated_at))/(maturity_at - fabricated_at)) as shelf_life", Time.now).
where("((100*(today - fabricated_at))/(maturity_at - fabricated_at)) <= ...
0
votes
1answer
61 views
How to pluck a camel case column
I'm trying to pluck a column from a table. The command seems to be failing because my column name is in camel case (practiceType). Here are my error, model and schema:
> Task.pluck 'practiceType'
...
0
votes
1answer
50 views
Database field refuses to be an integer - Rails/Postgres
I am creating a join table, broadly following the Railscast: http://railscasts.com/episodes/17-habtm-checkboxes-revised?view=asciicast
I cannot set the has_many records on the object and get the ...
0
votes
2answers
125 views
Rails Console Killed After 15 Seconds in Production
When I run a Model.all query (e.g. Product.all) for a table with a few thousand records, the Rails console is killed after 15 seconds. Can I extend this threshold (I assume) or in another way run my ...
0
votes
0answers
32 views
Rails ignoring miliseconds when compare date inside “order”
I'm having a trouble that I can't solve by myself, hope you can help me.
The problem
Currently I'm trying to get the Posts that user doesn't read yet, in other words, I want the posts that attends ...
0
votes
1answer
28 views
Issues with rails, postgres, timezones and scopes
We're seeing some funky stuff when trying to do scopes in Rails 3 in regards to timezones. Let's say we have an attribute called start_at of type date time. In application.rb we have ...
0
votes
2answers
62 views
how to group by month in postgresql and rails 3
I have value like 2014/03/01, 2014/02/20, 2014/02/19, 2014/02/18, 2014/01/19 ...
And I wanna get sum(price) by month. For first month, second, third month, ...
Using rails 3 & postgresql.
I ...
-2
votes
1answer
42 views
sql strip non-number characters to do avg (average) function on column like “$12.39”
I'm using Rails 3 & postgresql
I have column like -> formatted_price: "$17.99"
How can I use avg on this column?
I tried :
@items = Item.where(:user_id => @category.user_id, :asin => ...
0
votes
1answer
47 views
Upgrading to Maverick Owned Me: fe_sendauth: no password supplied
I am having issue with postgresql have upgrading to Mavericks like many users out there. I was able to install the pg gem.
I ran pg_ctl -D /usr/local/var/postgres -l ...
1
vote
1answer
94 views
Eager loading associations with complex query
Rails 3.2.13 with PostgreSQL
We are trying to optimize the below model code, which retrieves a set of e-commerce Orders from the database, based on user defined filtering criteria.
The user can ...
2
votes
1answer
187 views
server version: 9.3.2; pg_dump version: 9.1.9 rails with postgres
I am using rails with postgres database, I am trying to do a rake db:migrate and I obtain this error.
server version: 9.3.2; pg_dump version: 9.1.9
pg_dump: aborting because of server version ...
0
votes
0answers
26 views
`postgresql_connection': No database specified. Missing argument: database [duplicate]
Hey guys im trying to run my rails server
rails s
it prints out this error
postgresql_connection': No database specified. Missing argument: database
this is my database.yml
development:
...
1
vote
1answer
129 views
Call Database function in server with ruby on rails [closed]
I have a Postgres database on my server. This db has a bunch of tables, but the logic of everything is built up in functions on this same database; I have a website in php that calls these functions ...