I have a rails app that requires multi-table inheritance for which I am using the CITIER gem which itself requires the rails_sql_views gem to produce database views representing objects.
So far, so good. All this works like a charm on my local machine using sqlite3. When I try to deploy the application to Heroku, however, I am neither able to perform a database migration nor able to access the rails console.
The reason seems to be that the rails_sql_views gem tries to access some methods of PostgreSQLAdapter which are claimed to be non-existent. However, when I check the files of the rails repository, I can find these methods in the code. What is going on here?
When I try to run "heroku run rake db:migrate", I'll end up with the following error trace:
Running rake db:migrate --trace attached to terminal... up, run.1 rake aborted!
undefined method `tables' for class `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rails_sql_views-0.8.0/lib/rails_sql_views/connection_adapters/postgresql_adapter.rb:5:in `included'
/app/vendor/bundle/ruby/1.9.1/gems/rails_sql_views-0.8.0/lib/rails_sql_views/loader.rb:12:in `include'
[....]
This looks like an incompatibility between sqlite3 and postgres adapters with that gem. You should try to keep development as close to production as possible. Try installing postgress locally https://devcenter.heroku.com/articles/local-postgresql and see if you get the same error locally. If you do, consider writing a detailed bug report and sending it to the author of the Gem, or attempt to fix it yourself and send a pull request.
Related
On rake db:migrate, I am getting following error.
ruby-2.2.1/gems/activesupport-4.0.2/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
My rails gem gem 'rails', '4.0.2'
What's the solution for this?
From your error, it sounds like you are trying to use a Postgres database with your rails project. Basically, postgres runs separately from your rails project. You need to make sure you have:
a) installed postgres using something like homebrew
b) found a convenient way to start your postgres server when you need to (I recommend the one on postgresapp.com)
c) actually started the server before running the command that's producing this error (e.g., through opening the postgresapp or in a separate terminal window)
Conceptually, think of it this way: you can't migrate (e.g. 'change') a database that's inaccessible because the postgres server is down. That's what the error means.
As an alternative, you can use SQLite instead of Postgres. SQLite does NOT run as a separate process (https://www.sqlite.org/serverless.html), so you will run into these problems less. However, in your ruby code, you will need to pay attention to exactly how to configure your app for a postgres database or a sqlite database, whichever you choose. Here is a great SQLite tutorial for initial set-up:
http://www.integralist.co.uk/posts/active-record.html
Hello I am just getting started putting up a test database. I am using the preloaded rails environment from digital-ocean if that helps anything.
So I have just cloned my application from github and went rake db:create. When I did that it says there is an undefined method each for SQLite. I am not using sqlite though? I have specified PostgreSQL as the adapter.
I am a noob so sorry If this is a dumb question. Thank you in advance.
Use:
rake db:create
Not
rake:db create
I removed SQLite using gem uninstall sqlite3 then restarted the server. Everything started to work after that.
I've inherited a Rails application that has no migrations and no schema. The Rails application was created off of multiple databases created years ago and all the Rails app does is it uses ActiveRecord to fetch data from the database.
I know in order to prepare a database for testing migrations have to be in place for Rails to set up the necessary testing environment. I'm trying to use a test suite that has rspec, capybara, selenium-webdriver and factory-girl but I can't get the configuration working properly
If anyone could give me any suggestions or advice on how I would go about doing this, that'd be great!
Thanks
UPDATE:
When I run bundle exec rspec spec I get an error related to selenium-webdriver saying this:
warning: already initialized constant Zip::VERSION
/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
When I run bundle exec rspec spec without the selenium-webdriver gem I get the same error as above:
/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
And if I just run rake I get this error:
Errors running test:units! #<NoMethodError: undefined method `[]' for nil:NilClass>
In previous apps when the same database data has been required by everyone we've used seed_dumper & rake db:seed:dump to populate the seeds file and then rake db:seed.
For this app, using the Comfortable Mexican Sofa CMS gem and the fortress plugin it would be nice to do the same. Only seed_dumper only dumps the users - nothing else.
seed_dump (the 'parent' gem) gives the following error:
rake aborted!
NameError: undefined local variable or method `cms_manageable' for Comfy::Cms::Page(Table doesn't exist):Class
/usr/local/rvm/gems/ruby-2.0.0-p247#global/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/path to my app/app/models/comfy/cms/page.rb:9:in `<class:Page>'
Any ideas or alternate methods would be appreciated. Cheers.
Now using only gem 'seed_dump' (not seed_dumper), running the command bundle exec rake db:seed:dump works for exporting seed data.
I'm working on a project and I added a migration to add a project_page_description field to a Company Model. When I've ran the migrations,
#company = Company.first
#company.project_page_description
works locally, but any time I attempt to access project_page_description after deploying, I get an undefined method error. Why does it work locally but not remotely?
I've deployed all code so the codebases are identical, I've ran all migrations, I'm using Bundler and Capistrano, and I'm deploying to a CentOS server.
Also, besides stop programming, what can I do to stop this from happening again?
Looks like the migrations have not been run. Maybe you ran them using the development environment? Try running them like so: RAILS_ENV=staging bundle exec rake db:migrate.
Check your bundler groups, application config, and environment initializer files, maybe you have something defined as being development-only and not staging? Also try opening a console up on staging and trying to manually load and invoke the module that's not found. Remember that require returns true if the module was not already loaded.