Rails 3: Rails console not opening - ruby-on-rails

Suddenly, I'm not able to open the console or anything else related to the ActiveRecord in my app.
I always get this error:
~/Code/act(master) $ rails c
/Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure': Could not find table 'wsps' (ActiveRecord::StatementInvalid)
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `columns'
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/base.rb:679:in `columns'
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/base.rb:692:in `column_names'
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/validates_lengths_from_database-0.1.2/lib/validates_lengths_from_database.rb:20:in `validates_lengths_from_database'
I've tried this solution https://rails.lighthouseapp.com/projects/8994/tickets/99-sqlite-connection-failing with no effect.
What am I doing wrong here? Even when I checkout version who used to work from github I get the same error.
Regards,
Thanks

Try
rake db:migrate
I am assuming either you started in a new folder, or you added a new migration. The error states clearly that the table wsps cannot be found.

Related

ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException "DESC tablename, does it exist?" error while running migrations for test setup

I am trying to setup database in test environment. But I am not able to migrate the database
I looked on internet for hours. Even though this is a common problem, none of the solutions provided worked for me. Most common cause of the problem posted was wrong credentials could be posted in database.yml file. I checked that too. My databse.yml is correct.
To do this I the executed the rake
'rake db:migrate RAILS_ENV=test'
On executing the above command, it shows error as:
rake aborted!
ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException: "DESC articles" failed; does it exist?
/usr/local/rvm/gems/ruby-2.4.1/gems/activerecord-oracle_enhanced-adapter-1.7.8/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:231:in `rescue in describe'
Caused by:
OCIError: ORA-04043: object articles does not exist
metadata.c:175:in oci8lib_240.so
/usr/local/rvm/gems/ruby-2.4.1/gems/ruby-oci8-2.2.5/lib/oci8/metadata.rb:2053:in `block in describe_table'
/usr/local/rvm/gems/ruby-2.4.1/gems/ruby-oci8-2.2.5/lib/oci8/metadata.rb:2052:in `times'
/usr/local/rvm/gems/ruby-2.4.1/gems/ruby-oci8-2.2.5/lib/oci8/metadata.rb:2052:in `describe_table'
Please help.
Thanks inadvance.
Are you working on multiple tenants with different databases and switching them using establish_connection method?
Perhaps from mater database to child client database, if you grant access to any table, it will work but if you miss then it can such a kind of error. (I experienced also)
You need to check inside rails c by ActiveRecord::Base.connection.tables.includes? 'articles' which must return true.

ruby on rails saving record create problems

I am facing the below error when saving the record into database after I added the new column to migration that is "fathername"
NoMethodError in StudentController#admission1
undefined method `fathername=' for #<User:0x7ffcd42a3a40>
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:255:in `method_missing'
/root/ansipro342/app/models/student.rb:141:in `create_user_and_validate'
/root/ansipro342/app/controllers/student_controller.rb:62:in `admission1'
Request
Parameters:
{"student"=>{"first_name"=>"Salman",
"fatheroccupation"=>"Lecturer",
"address_line1"=>"",
"address_line2"=>"",
"country_id"=>"141",
"roll_num"=>"100",
"is_email_enabled"=>"1",
"gender"=>"m",
"fathernic"=>"",
"biometric_id"=>"",
"admission_date"=>"2015-12-11",
"date_of_birth"=>"2010-12-11",
"fathername"=>"Kamran",
"nationality_id"=>"141"}
even the fathername column already exists but its showing the error pls help, I dont know what is wrong?
I think you just have to run the migrations rake db:migrate ! This is typically happening when you try to set an attribute value and this attribute column doesn't exists in the database.
Hope it helps :)

Uninitialized Constant Admin on Heroku

I have a fresh app with only a few gems. Devise being one of them of course. And when I make an Admin model via Devise's Option 1 give here
... and upload to heroku, I am unable to run a db:migrate due to the following error:
rake aborted!
uninitialized constant Admin
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in block in constantize'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:ineach'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in constantize'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise.rb:256:inget'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:77:in to'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:72:inmodules'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:89:in routes'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:156:indefault_used_route'
etc...
Does anyone have any suggestions?
Created another fresh rails app and everything is working now. I believe the problem might have been that I created my Admin model with a capital "A" and some code was looking for an admin model with a lowercase "a"

Rails 3.1.0.rc4 + Postgres - cannot read from or write to database after reboot

I've just started to write an application using the latest version of Rails and PostgreSQL. I created the database, added required gem, configured database.yml file and started with two models - User (this one used Devise for authentication) and Group. I created an additional controller for start page (simple one - only to display list of links). Everything seemed fine, I was able to add test data to the database - until I came back this morning and wanted to continue work.
As long as I stayed on the home page, everything looked just like yesterday. But when I tried to access group list, I got the following error:
Routing Error
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
There was no additional informations on the page, so I looked into Webrick console and saw the following:
ActionController::RoutingError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map):
app/controllers/groups_controller.rb:1:in `<top (required)>'
The first line of my controller is, as usual:
class GroupsController < ApplicationController
I looked at the other actions, and the result was the same: unexpected nil object. Same issue occured while trying to perform any action on User.
I suspected it's a database problem (because it didn't affect the controller that wasn't using database at all), so I went to rails console to see if I could add entries manually. I couldn't.
ruby-1.9.2-p180 > group = Group.new
(some SQL)
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/persistence.rb:320:in `attributes_from_column_definition'
from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/locking/optimistic.rb:69:in `attributes_from_column_definition'
from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/base.rb:1525:in `initialize'
from (irb):1:in `new'
from (irb):1
from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands/console.rb:45:in `start'
from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands/console.rb:8:in `start'
from /home/lite/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I looked into the most top file (persistence.rb) and searched for line 320.
319: def attributes_from_column_definition
320: Hash[self.class.columns.map do |column|
321: [column.name, column.default]
322: end]
323: end
This definition gave me a little idea what might be happening, so I ran one more command in the console (Group.inspect) and I got error on the following line:
attr_list = columns.map { |c| "#{c.name}: #{c.type}" } * ', '
It seems like I'm not able to access the columns of my table, but I have no idea why. I'm logged in as the same user, on the same machine, using the same operating system and kernel. Out of curiosity, I created another application and it didn't work after the reboot either.
I've spent now four hours looking for answer, but I couldn't find anything related. What might be causing this problem and how to fix it?
I have found the guilty one: small gem called 'automatic_foreign_key' I used to automatically detect foreign keys. When I rollback the changes it made, removed it and altered the table manually, I had my application working again.
Thank you all for help!
Maybe Group is a reserved word in this version of postgresql or rails. rails-3.1.0-rc4 is the most fresh version of rails. Generate another dead simply model to check it.

FriendlyId: undefined method `use_slug?' for nil:NilClass

I am creating a new environment besides production. I copied all the configurations from my production environment, changing what needed to be changed.
As it is the servers do start, but when I do a query I get this exception:
NoMethodError (undefined method `use_slug?' for nil:NilClass):
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:65:in `slugged?'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:43:in `finder_class'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:37:in `finder'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/finders.rb:32:in `method_missing'
vendor/gems/friendly_id-2.3.4/lib/friendly_id/active_record2/slugged_model.rb:149:in `find_one'
app/controllers/home_controller.rb:5:in `index'
The line in question does this:
#page = Page.find("home")
I am using FriendlyId 2.3.4, and Rails 2.3.4. The code is the same for the production environment, and it's working just fine there, so I'm not really sure on what's going on here...I could see that the line where the exception gets raised does
friendly_id_config.use_slug?
so for a reason I'm not aware of friendly_id_config is nil.
Thanks for any guidance on this problem
I found a workaround to this issue by loading the server using the production environment.
I was trying to use a 'preprod environment, and somehow FriendlyId didn't like that strange environment.
Load the app using RAILS_ENV=production and it worked fine.
Not a solution, but at least could move on...

Resources