I have a rails which seemed to be working previously but now after some changes when I go to the root page it takes it infinitely to load it, it just doesn't load it. There're nothing useful in the console either. How can I find out what prevents it from loading the main page? Is it about profiling?
Check your Rails logs, eg. development.rb. You can put logger.info, or puts statements in your environment.rb, development.rb and application.rb files to see how far Rails is getting in the boot process. You can also create a dumb initializer named 00_start_init.rb with a logger.info or puts statement to see if you're getting as far as initialization. I've found that useful before.
To really understand where you application is hanging, you need to understand the Rails initialization process. Here is the documentation for Rails version 4.2. http://guides.rubyonrails.org/v4.2/initialization.html. Similar documentation exists for every version of Rails. You can take advantage of understanding the boot sequence by placing log statement at various point in the process.
I'm assuming you're in the development environment. If so, and the console loads, it's likely not a configuration problem. It's more likely a problem with your controllers or models. If the console won't load to a prompt, then it's likely a configuration problem in application.rb, development.rb, an initializer, etc.
You mention profiling, but provide no details about it. I can't even guess what you're referring to, so the answer is "maybe?". If you can post the code changes you made since the app last loaded in the browser, that would make it much easier to help you trouble-shoot.
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.
Ran into this error message whilst developing tonight: SQLite3::BusyException: database is locked:
I have two models:
Podcasts have many Tracks
Tracks belong to Podcasts.
Podcast files are hosted on mixcloud.
To create a Podcast:
user submits a url for a podcast on mixcloud
rails app grabs json feed associated with url
json is used to set attributes (title, image etc) on the new Podcast object
I'm trying to get my rails app to take advantage of the fact that the json feed also details the names (and artists) of the Tracks that belong to this Podcast.
I thought the following before_validation method would automatically create all associated Tracks whenever we create a new Podcast.
class Podcast < ActiveRecord::Base
attr_accessible :mixcloud_url, :lots, :of, :other, :attrs
has_many :tracks
before_validation :create_tracks
def create_tracks
json = Hashie::Mash.new HTTParty.get(self.json_url)
json.sections.each do |section|
if section.section_type=="track"
Track.create(:name=>section.track.name, :podcast_id=>self.id)
end
end
end
end
How can I get round this? It looks like rails (or sqlite3) doesn't like me creating new instances of an associated model in this way. How else can I do this? I suspect this is as much a rails problem as an sqlite3 one. I can post more code if it's gonna help.
For anyone else encountering this issue with SQLite locking in development when a Rails console is open, try this:
Just run the following:
ActiveRecord::Base.connection.execute("BEGIN TRANSACTION; END;")
For me anyway, it appears to clear any transaction that the console was holding onto and frees up the database.
This is especially a problem for me when running delayed_job, which seems to fail at closing the transaction quite often.
SQLite is not really supposed to be used for concurrent access which is the issue you are running into here. You can try increasing the timeout in your database.yml file which may be a workaround for you in this case. However, I would recommend you switch to another database that supports multiple connections like MySQL or PgSQL.
For me...the issue I had was that it seemed that the Rails Console I had open for a while was locking up a connection with SQLite.
So once I exited that console, and restarted my webserver (Thin) it worked perfectly.
I tried #trisweb's suggestion but it didn't work for me.
I had the same
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is
locked: INSERT INTO "users" ("created_at", "email", "name",
"password_digest", "updated_at") VALUES (?, ?, ?, ?, ?)"
issue. I tried every way around found in Google and I failed. The problem was solved for me when I closed my SQLite Database Browser.
Make sure you don't have 2 guards or several consoles running.
If you want make sure desperately see the "No Name's" answer above.
You can also try increasing pool:
for example:
change test section in your config/database.yml as below
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 50
timeout: 5000
Probably you have a Rails console open on another bash, if so you have to close it (ctrl+D).
actually for me, I found killing rails help to fix this problem.
use "ps aux | grep rails" to find out ongoing rails process id.
then use
"kill -9 [rails-pid]"
to kill processes.
Then it will work
It is most likely not related to rails code. Using at the same time the console with the sandbox option (rails console --sandbox), makes the problem systematic with SQLite, since the console is basically waiting to quit to rollback everything.
The solution above from #trisweb will not work in this case, but quitting the console will.
my trouble is: I opened a database management program named "DB Browser for SQlite". Closed this database management program, and problem solved.
Yes this is an old question and there are many answers on here already. But none of them worked for me, meaning it took me a long time to finally figure out the problem. I found what worked and will share it in case it is what might be causing the problem for you too.
I was using the SQLITE Browser (its a GUI database browser). I will refer to it as "GUI" here (to prevent confusion with the word browser being your localhost::8000 chrome browser or whatever.
http://sqlitebrowser.org/
I was monitoring what was being written to the database and had the GUI open while my rails app ran in my chrome browser. I would refresh the GUI to see if it was adding the data as I expected it to.
As a matter of debugging I had decided to delete a row from the SQLite GUI so I could see if my app would react appropriately to the row being missing now.
As it turns out, the SQLite Browser does not actually delete the row (causing confusion on my end as to why my app was acting like the row was still there, even though it was visually missing on the GUI). Anyway after 30 minutes of frustration I closed the SQLite GUI and then got a notice that asked if i wanted to save any changes to the database that I made. I naively clicked "No" and closed the app.
Apparently what happens is that the GUI then locked the database because there were rows in my database that had been sort of "soft-deleted" without committing to the delete. So the GUI was (for lack of a better term) holding the database in Limbo.
This explains why a) my app wasnt acting like the row was missing, because it hadn't actually been deleted yet, and B) explains why the database locked up. It was still waiting for me to commit the deletes.
So to solve the problem, I simply opened up the GUI once again and deleted the same row and then closed the GUI and this time I clicked "Yes" when asking to save changes to the database. It saved the delete and unlocked the database and now my app works!
I hope this helps someone else that might be having the same issue but was using the SQLite Browser GUI interface. This might be what is locking your database.
I had the same issue. For those with SQLite Database Browser. I did not need to close SQLite Database Browser. I only had to click the "Write Changes" button. It is highlighted and needs to not be highlighted.
SQLite has troubles with concurrency.
I changed sqlite on Postgresql and the issue is gone
This happens when you make any changes manually directly into the SQlite DB Browser (like delete a row or change the value of any column) and forget to save those changes. Any changes made need to be saved (ctrl + s). If not saved, SQLite locks the Database until u save those changes.
I did the same and my issue got resolved!
I was using DB Browser for SQLite and rails console simultaneously. Closing the DB Browser for SQLite fixed the issue for me.
try restarting the server
or closing any running rails console,
worked for me
Your .sqlite3 file must be saved.
Go to DB Browser for SQlite and make ctrl+s or File->Write Changes.
Try wrap cycle in a single transaction:
def create_tracks
json = Hashie::Mash.new HTTParty.get(self.json_url)
Track.transaction do
json.sections.each do |section|
if section.section_type=="track"
Track.create(:name=>section.track.name, :podcast_id=>self.id)
end
end
end
end
(see Track.transaction)
You may also have enabled threads when parallelizing your tests. Remember to disable the option in test/test_helper.rb :
parallelize(workers: :number_of_processors, with: :threads)
to
parallelize(workers: :number_of_processors)
https://edgeguides.rubyonrails.org/testing.html#parallel-testing-with-threads
1. bin/rails console
2. exit
Go into the rails console and type exit, and press enter.
Done!
Sadly, many of these solutions did not work for me.
I was lucky. Since this was happening while I was running tests, I just did a simple DROP and CREATE on the DB.
$ rake db:drop RAILS_ENV=test
Dropped database 'db/test.sqlite3'
$ rake db:create RAILS_ENV=test
Created database 'db/test.sqlite3'
$ rake db:migrate RAILS_ENV=test
== 20220310061725 Tables: migrating ======================================
....
== 20220310061725 Tables: migrated (0.0027s) =============================
...etc
Not the best solution, but it works in a pinch.
If this was in your development environment, and you HAD to do this, I would seriously invest in creating a data seed for your DBs so you can get up to speed again.
rake db:drop
rake db:create
rake db:migrate
rake db:seed
I'd like to talk about the case of rails controller opened.
In my own case, I had opened rails controller with the --sandbox option.
After reading that I had to close the rails console. Closing alone didn't fix it. I had to restart my PC to make sure all processes got terminated. That resolved it.
I could use a little help trouble shooting this problem.
When using the app to create a new record nothing is being saved to the database.
There are no visible errors presented.
Dropping to the command line, and using the console with the same production environment, I can create a new object and save it (I have to bypass validations). If I look in mysql database I can see the record that I created from the console.
App works fine locally.
Any thoughts on what might be the problem?
Rails 2.0.2
Sounds like a validation error.
In your controller, try using save! (with the bang) to see if will throw a meaningful error.
I am not sure what code you have in the controller, but this might help show the problem
if my_object.save
log.debug 'object saved correctly'
else
log.debug my_object.errors.full_messages
end
Good luck, if this doesn't help. Try posting the relevant controller and model code.
Have you double checked that the request (with params, etc) works correctly in development?
If not, perhaps looking at the production log file will tell you where the request was routed (e.g. which controller and action, and with which parameters).
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.