How to clean RoR database yml cache? - ruby-on-rails

I've just set out to creating my first RoR project, using MySQL. Obviously after the first visit to browser the site informed me about not being able to connect to the DB with the current settings. I've quickly updated them in the config/database.yml, however it still complained about the old settings.
Eventually, it updated and was working fine, but I'm sure there's a cache somewhere that could have been cleared to make this less of a nuisance.

I have commented it earlier, Now adding it to my answer ;)
It seems like you have not restarted the server after done the changes in database.yml. Because, database.yml is being loaded once at the time of server start-up. So please try with restarting your rails server.

Related

Heroku "We're sorry, but something went wrong" after Postgres migration

I recently did Heroku's requested database migration from a "shared database" to Postgres. I followed Heroku's directions carefully, and it all went fine until the last step: removing the old shared database. At that point, my app went down with the "something went wrong" message, and it's been down ever since (going on two weeks now).
Note that the app was still working after the step in which I switched to the new database, and according to "heroku config", it is using the new database. It shouldn't care about the old one disappearing. The logs say nothing other than 500 errors.
I submitted an urgent support request to Heroku, but they were not helpful. They just said that my data is still there but, "Your application isn't logging so it's not clear why this is happening but it doesn't appear to be due to the migration." That was a week ago, so it's not looking like they're going to do anything more.
I agree that the problem shouldn't be due to the migration, but given that I've made no changes to the app except the migration, and that it died exactly when I removed the old database, I don't see what else it could be.
My app is probably pretty old at this point (Rails 3.0.3), so my only thought now is to update everything to the latest versions and redeploy. The app is used to record merit badges and rank advancements for our local Boy Scout troop, so I really need to get it running again. Any advice would be greatly appreciated.
My first instinct would to db:pull the heroku hosted database. (make a copy).
Then try to start your app locally.
Heroku has fixed the problem. My hypothesis was correct: my app was so old that the migration procedure did not actually update it to use the new database. They say that they'll be applying the fix to their other old apps now.
If the app started failing the moment you removed the shared database, it means that your app was still connected to this database and was never connecting to the new one. It sounds to me like you did not run heroku pg:promote HEROKU_POSTGRESQL_<color of new database> --app <your-app>. Can you try that?
Edit:
Based on the further info provided in your comments, it's possible that this is a potential issue in the aspen and bamboo stacks (that only affect a few customers). The thing to try now is a new deploy. Try making a trivial change - maybe a newline in your project README - and deploy the app again. This will force a slug recompile that will write out a new database.yml using the correct DB.
Even better would be to migrate to the cedar stack though

How do I acess/open/edit a .sqlite33 file?

I'm completely new to Ruby on Rails, have never worked on it, but I am supposed to take over somebody else's old project. He designed a webapp that logs into a website/server online, extracts data from it daily and performs calculations. However, the application has not been running for quite some time, so now when it tries to display statistics, the page crashes. It uses data from a 5 week period and currently only has data for 2 days.
I need to manually insert data for the missing weeks in order to get it up and running again, but the problem is I don't know how to find/access its database, nor how exactly to use Ruby on Rails. I found several files in the db directory of his project, however they were mostly .sqlite33 files or just 'files'. I downloaded sqlite precompiled binary for Windows and tried to use it, but not sure what to do. I also downloaded and tried using SQTView to open the files to change the tables, but I have had no luck.
How can I tell which file is the main database and how do I edit it? And what are .sqlite33 files? Thanks.
EDIT
The application produces a
TypeError in HomeController#index
"nil can't be coerced into Float"
It links the error to a line in the code, but the only reason the error happens is because there is no data in the table for the time period that the variable in this line of code tries to use. That is why I want to manually update it with values.
I think that Sqliteman might do the trick and thank-you for explaining all of this to me. I just have to confirm it works after editing.
EDIT2
Okay, so I had a small revelation while experimenting on his app. It turned out that the page crashed because of empty values for full weeks. If I used the app to gather data for at least one day per week up until this week, then the app worked.
Is there a way I can populate all the missing days without having to manually click the days in its calendar because it takes a good 20-30 seconds for it to load?
Thank you very much for your help.
A Rails application's database is defined in config/database.yml - though the database itself and the scheme are in the db folder. In database.yml you'll find three database configurations - development, test and production - so make sure to choose the right file.
I've never heard of .sqlite33 files, but to edit SQLite files manually I recommend SQLiteMan. But I don't recommend editing it manually.
What I do recommend is to check if you are running the app in development or production mode, as the two mods use different databases. Try to run it in the other mode.
If that doesn't work, try saving a copy of the database files, and running the commands:
bundle install
bundle exec rake assets:precompile
rake db:migrate
rake db:migrate RAILS_ENV="production"
(if you're using Linux, you might want to also run the first command with sudo)
Those commands make sure all the required gems are installed, that the precompiled assets are up to date, and that the database fits the schema. If you are running that application on the same machine and with the same database as the ones the other guy was using, than those commands shouldn't be necessary, but if you have moved the application to your own machine, or used an used an outdated db file, than those commands might fix the crash.
At any rate, if you tell us what error the application is producing we might be able to provide more assistance.

Needed help with deleting rails cache

I have been given a project of editing a website which is coded in RoR.
However, the changes which i make in the view file is not visible immediately after a hard refresh but after 15-20 mins, the changes reflect. I am guessing this has something to do with the RoR caching system.
Can someone please help me out ? The changes i made are purely HTML based like changing HTML attributes, filenames etc...
When the app is running in production environment, it caches everything in memory. You need to restart the application to reread all those files.
If you're running passenger you can restart the app by updating/touching/creating the tmp/restart.txt file. It's enough if you just update the modification timestamp:
touch tmp/restart.txt

How did this Ruby on Rails app get deployed?

I have a Ruby on Rails app running on my server, and I can't figure out how it was deployed (someone else set it up).
The app is located in /var/www/myapp. Before it was deployed, I had been able to go in there and make minor edits to the app. The person helping me out with RoR then "deployed" it. It was unclear what deploying actually did, since it points to the same database and is on the same server. However, I can no longer edit it (or at least, the files I am editing are not being pointed to by the server).
Any way to figure out how this thing was deployed so I can take it down to edit it? Or should I basically just start over?
Was it maybe running in development mode before, and now it's in production? When it's in development mode, all of the files are loaded on each request, so your changes show up immediately. In production mode, you have to restart the server to see your changes.

Rails app unable to save anything after deployment

today I uploaded my app to server, and after seting it into development mode, and running of course rake tasks (rake db: migrate, and rade db: migrate RAILS_ENV="production") and well it just doesn't save anything.
The problem happens when I try to create any new items, it just goest to the listing of models...
Your question is very vague. I believe you're saying the app writes files to the server's hard drive. If that's what you're asking, I think the best guess is that something's wrong with file system permissions. Unfortunately, I can't say what is wrong without more details.
i solved it.
reason i asked was because i absolutely went through each and every one of my potential problems and took care of them, and well in the end none of them were the reason of such a failure. so then i went to the basics
and i basically had to clone my development environment on the production machine.
so i had to downgrade rails a couple of versions, and some gems too.
that took care of it, everything went on smoothly, so if anyone ever encounters such mysterous failures, give this a try.

Resources