Tagged Questions
1
vote
1answer
28 views
Sorting by virtual attribute in Rails
I'm developing with Rails 3.2.8
I want to convert this sorting to Rails scope.
class Doc < ActiveRecord::Base
has_many :denotations
def same_sourceid_denotations_count
...
0
votes
0answers
19 views
Data not saved with attr_encryptor
I would like to encrypt data in my project so I use https://github.com/danpal/attr_encryptor
I use this gem like this for my User model for example :
attr_accessible :name, :mail
attr_accessor :name
...
0
votes
0answers
44 views
Rails PG::Error: ERROR: value “214524245325432453” is out of range for type integer
This error is is triggered by PG before any validations like "greater_than". How can I handle this the Ruby way and not in the controller?
1
vote
0answers
16 views
Rails migration is always inserting whitespaces or changing the ordering of columns in the schema
There is a frustrating issue where my rails migrations update the schema with whitespaces and the position of the table's columns.
So most times when I run bundle exec rake db:migrate it will do one ...
1
vote
1answer
35 views
Random “SELECT 1” query in all requests on rails
I'm profiling my rails 3.2 app with miniprofiler, and it shows me a
SELECT 1
query at the beginning of each page load or ajax call. It only takes 0.4ms, but it is still a seemingly unnecessary ...
3
votes
3answers
117 views
Cannot connect to two postgres databases in rails 3.2.
I've tried a few methods found on stack overflow for connecting to two database in rails two however non of them are working. Here's what I've got at the moment:
In the database.yml there's two ...
2
votes
0answers
70 views
How to make an array sum of month from Postgresql query to Rails 3
I'm new in programming but here's the thing: I'm trying to make rails app which takes data from postgresql database and shows summary in jqPlot chart, but I am having trouble with my queries. I need ...
0
votes
1answer
22 views
column spree_preferences.key does not exist
When I run
rake db:migrate
I get the following error message.
PG::Error: ERROR: column spree_preferences.key does not exist`
Anyone can please tell me how to fix this error.
1
vote
1answer
45 views
Active Record sort by min value
I have a few models, City, Hotel, and Room. City has_many hotels, hotels has_many rooms. Each room has a price. I'm trying to sort by the lowest price room, asc and desc.
In my results, I'm also ...
0
votes
1answer
47 views
Creating a general index when using nested routes
I am new to rails, and for the first time I am working with pgsql. The way my project is set up it requires that a song cannot be created with out an artist. To accomplish this I used nested routes so ...
0
votes
0answers
25 views
Rails code working with sqlite but fails on heroku with postgres
Can any one suggest why the following query might be raising error:
TypeError: can't dump anonymous class Class: INSERT INTO "emails" ("content", "created_at", "email_from", "email_to", "filter_id", ...
0
votes
2answers
22 views
How to write update all based on row value for date type column?
I have datetime column data type in ReminderDetail model, and I want to update_all values belonging to that column. I have written below query
ReminderDetail.update_all("reminder_date = ...
0
votes
2answers
72 views
Rails Postgres - Datetime value won't save into Datetime column
My model has a datetime attribute (Postgres) and I am attempting to create a new record via form submission in my Rails app.
The form I'm submitting contains a text_field for that datetime attribute. ...
0
votes
0answers
25 views
Storing rails code in database. Upgraded from Rails 2 to Rails 3
I have the following piece of code illustrated as below. Was working in my Rails 2 application but having upgraded to Rails 3 it not longer works.
When I render this code, I'm getting like,
...
0
votes
1answer
57 views
Ruby on Rails page load error “could not connect to server: Connection refused (0x0000274D/10061)”
When I run my "rails server" command, and go to my web page, I get this error http://s7.postimg.org/jcxqxl3gr/image.png I am using Postgresql and have only installed the twitter-bootstrap-rails gem. I ...
0
votes
2answers
33 views
Heroku PostGres database update structure without deleting data
If I make database changes locally, and then use postgres with heroku, what does pushing the database actually do? Update schema, data, or both? There is no information on what actually happens when ...
1
vote
1answer
33 views
Heroku Asks for PG gem when I have Mongoid
I'm receiving the following error
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (LoadError)
whenever I ...
0
votes
0answers
63 views
Using Sqlite3 test database and Postgres dev/production database in Rails
I currently have a rails project which I deploy to a production server which uses a postgres database. I develop my rails project in Windows, which means that if I want to test locally, I have to ...
0
votes
2answers
37 views
Read data from other postgres database
I have a Rails app A with a postgres database. I also have another Rails app B with a postgres database. Now I want to reuse some of the data of app B in app A. What is the best way to import that ...
1
vote
1answer
41 views
Cannot get Postgres.app connection
I'm using Mountain Lion and want to switch my rails app from SQLIte to Postgres so I can deploy on Heroku. I have installed Postgres.app and it's working fine if I open it with the path suggested:
...
0
votes
1answer
40 views
Finding records based on no returned records from a related table
Dealing with two tables in Postgres: Members and Memberships. Memberships have an end_date column that can be NULL if the membership is still running. As soon as it has ended, or the end date is known ...
0
votes
0answers
42 views
update query not updating in postgresql
Not updating postgresql database when update_all using
@change_stat = Notification.where("fb_id = ? AND active = ?",@current_user.fb_id,true)
@change_stat.update_all(:active => false)
1
vote
1answer
56 views
What happens when a query gets very large results
most usages/tutorial/manuals explain how to use the methods in context of a manageable DB.
So if User.where( some condition) would return a result of tens or hundreds it would reasonable to think ...
0
votes
1answer
44 views
Foreign character issue with CSV import to Heroku Postgres DB
I have a rails app where my users can manually set up products via a web form. This works fine and accepts foreign characters well, words like 'Svölk' for example.
I now have a need to bulk import ...
0
votes
0answers
37 views
Going .pluck crazy. What is a realistic limit on query with array
I've used .pluck(:id) quite often (and map before it) to get a set of record ids. This is usually to get a set of related model records (e.g,, :people has_many :scores, as :assessed)
Lets say I have ...
2
votes
1answer
133 views
Unable to install pg gem (Rails 3 - Cygwin) - sh: : command not found
When I run
$ gem install pg
I get the following
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
...
1
vote
1answer
46 views
Rails: A database-independent datatype that's suitable for bitwise operations
I have a Rails app with a couple resources that I need to run queries on the involve bitwise operations. Right now, I'm using PostgreSQL, and I created a migration for my 'user' model that uses the ...
1
vote
0answers
24 views
Rails 3 Saving User Searches DataModel
I am working on a piece of my app where the client is wanting the ability for user searches to be saved (these searches are completed by the user completing a set of dropdowns and then entering in a ...
0
votes
1answer
70 views
How to populate join table for a HABTM relationship Rails 3, postgresql
So after searching long and hard for information that can help us, we've found it difficult to find an answer we can work with.
Our problem is that we have two tables joined through a HABTM ...
0
votes
3answers
72 views
Big Integers and Custom Validation
I'm somewhat new to Rails and I'm trying to learn about custom validations.
One common requirement in Brazil are CPF/CNPJ/RG fields. They are a type of identification number and follow a specific ...
0
votes
1answer
65 views
PG::Error: ERROR: operator does not exist: double precision = boolean
I have the following query executed in rails using find_by_sql
select LEAST(a,b) as min_value ,
CASE LEAST(a,b)
WHEN LEAST(a,b) < 1.0
then 1.0
ELSE 1-LEAST(a,b)
END
from model where type=abc
...
1
vote
2answers
55 views
Dynamic table columns based on user preferences
Scenario
Lets say a user is a salesman. The User model has many log_entries used as a daily log for sales data. The user also has preferences that allow them to select what fields are visible in ...
0
votes
1answer
295 views
PG::Error: ERROR: permission denied for relation schema_migrations
Not sure why I'm running into this error. I've setup postgresql properly, just ran a migration and then rake db:migrate and I'm getting the title error.
Here is my:
database.yml
development:
...
0
votes
1answer
35 views
Proper way to add forgeign keys in db?
So - I've been learning rails for the last 4 months and would like to think that I have a pretty good overview of it. Albeit, there are a few gray areas that I would like to make clearer. One being ...
1
vote
1answer
66 views
Postgres data type integer[] in ruby
ruby : ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
@user = User.find(1)
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
=> ...
2
votes
1answer
44 views
Can't Save IDs from other tables into current table in database upon creation of an object Rails, Postgresql
I'm having problems getting multiple ids to save properly into my database.
I have a listing that has two parameters: a listing id and a price.
I've tried changing the controller to accept the ...
-3
votes
1answer
51 views
How can I get 20 users and 5 articles from each user? [closed]
Users can have many Articles.
I want to get 20 of the most recent users and for each user, 5 articles.
I was reading on http://wiki.postgresql.org/wiki/Find_recent_activity but this seems overly ...
0
votes
2answers
48 views
Problems with belongs_to condition in model
I'm making personal money management app. There I have 2 models: Account and Transaction.
Transaction has belongs_to :account and Account has has_many :transactions.
When I had account_id column in ...
0
votes
1answer
82 views
Postgres stopped connection on 127.0.0.1
I know this subject has been discussed, but none of the answers have helped me. Sorry, for starting a new topic on it...and thank you to anyone who helps.
I have been developing on my local ...
2
votes
2answers
35 views
Is it normal/adviced to have “id holes” in my user table (rails 3.2/postgresql)
I am a total newbie, training myself building a basic Rails app on Heroku (using postgresql and as db client PGAdmin)
I have a basic user table with name, email, password...
I have noticed that when ...
0
votes
1answer
46 views
Calculate rank for multiple attributes
I'm building a motorsport timing app. As car's race around the track, Users input the split times for each Car into the app. The app then ranks each car at each split and displays this in my view.
...
1
vote
1answer
41 views
rails test and development databases are in different schema
I want to make benchmark tests but when I run
rake test:benchmark
I'm taking this kinds of errors
ActiveRecord::StatementInvalid: PG::Error: ERROR: relation "contests" does not exist
LINE 5: ...
1
vote
3answers
52 views
Static Read Only SQLite3 Database in Heroku
I will try my best to explain my issue.
I have a SQLite3 database file of about 50,000 records that I compiled and use in my app. This database is read only and is only used to query and pull data ...
0
votes
1answer
45 views
gem install pg only works as sudo
I have read a lot on this topic, but seems like nobody has had the exact problem I am having.
I am trying to install Postgres support for Rails 3 on Ubuntu. If I run:
sudo gem install pg
...
0
votes
3answers
132 views
Rails: rspec fails after switching to postgreSQL
I'm learning rails and following the Ruby on Rails Tutorial Book.
It had an extra challenge and taught me how to use postgreSQL instead of the default SQlite3.
However, since I have changed to ...
1
vote
4answers
58 views
Can't deploy to heroku [heroku log included]
I'm having trouble deploying to Heroku, I've installed postgresql but I don't think I've configured it properly. This may or may not be the problem, but I have a hunch it has something to do with it. ...
0
votes
1answer
119 views
Rails, CKEditor, PostgreSQL, image upload with Carrierwave
When I try to insert an image into my blog I select the Upload tag and select my file and Send it to Server. Then at the URL tab I select Browse Server and I get the following error:
...
2
votes
2answers
49 views
Calculate offset of a row
I am writing a server side on RoR, which uses postgresql.
Today I faced a feature, in what I need to identify the current offset of a row in the table. Client send me a unique identifier and I need ...
0
votes
2answers
267 views
Cannot run rake db:migrate, relation does not exist
I am trying to get a working app to work on linux 10.04 running on vagrant
I installed all relevant gems, installed postgresql 9.1.9 and when I am trying to run
rake db:migrate I am getting
rake ...
0
votes
1answer
39 views
Rails Article.find 1 raises ActiveRecord::StatementInvalid on legacy database
I'm creating a rails app over a legacy database table. Everything works fine locally, but on the server I hit this error whenever I do Article.find(1)
Could not log "sql.active_record" event. ...