How to make sqlite3 work in ruby on rails? - ruby-on-rails

I'm trying to start learning ruby on rails and install sqlite3. I actually installed sqlite3 however it doesn't function well like you can see at the bottom.
ruby 2.5.0p0 (2017-12-25 revision 61468) [x64-mingw32]
C:\Users\abc>sqlite3 --v
'sqlite3' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\abc>
Would you tell me how to solve this problem?

Switching to Ubuntu is easier than learning all the hacks required to get Ruby on Rails working on Windows. Once you switch you will never look back, and all the tools you need, like SQLite, will install very easily.

SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file.
Directly downloadable SQLite .exe file to maintain database SQLite then extract to a folder then open SQLite command toll where you can command for database creation, delete, edit or view
You need marked one .exe file, double-click to open then write command which you need.

Related

synching two databases in heroku rails app

I have crm rails application deployed in heroku so my database is postgresql. I have an iphone app which is using mysql database. Now what i need to do is to synch my iphone database with my heroku database.
Can anyone please help me on this is it possible to sync two different databases in heroku
Thanks in Advance
The way we did this was to do it manually
Yep, it's a real pain, but at least you know it's done correctly
--
Process
For migrating from Postgres to MYSQL is as follows:
"Backup" the database using pg_backups
Download the backup locally
In MYSQL (we used PHPMyAdmin), create a series of SQL calls to insert the respective data into the correct tables
Migrating from MYSQL to Postgres is, as much as I can determine, a similar process:
Download the SQL dumps of your MYSQL DB (I only know how to do this in PHPMyAdmin)
Configure those files to be "PG" ready
Send the SQL to your Heroku postgres db's
--
Notes
For specifics, I only have the following:
If you dump from Heroku, you'll not get a traditional SQL file; you'll receive a .dump file. To change this, you'll need to use pg_restore in the following way:
$ cd c:/your/postgres/install/pg_restore/location
$ pg_restore path_to_your_dump.dump > path_to_your_sql.sql
This will give you the ability to "read" the file, uploading to your db & importing as you wish. That's when the fun begins :)
Importing MYSQL
The way to import MYSQL into a PG db will have to be done manually
Although we've never done this directly (we only migrated from PG), there are several things you can do. Firstly, you can use the PG2MYSQL converter to give you an idea as to the syntax differences between MYSQL & PG
Then I would perform a "dump" from MYSQL in SQL format. This will give me the data required for PG. This will allow me to insert into my PG database (you might have to do this locally to give you the ability to determine the syntax), from which you can then patch in the MYSQL data
I understand it's not the most elaborate explanation - I hope it gives you some ideas

Database in Rails application

I cannot find where the database in my Rails application is located. I looked in folders like /db, /db/migrate, and /app/models, but cannot find the actual database that I can open to examine the data. Where is it located?
Try running rails dbconsole from the command line while you're inside your project directory.
If you're running a SQLite Db (which rails runs by default), you can download SQLite DB Browser (http://sqlitebrowser.sourceforge.net/), and open your db/sqlite3 file to view the actual data, or if you're using mysql, check out: http://www.sequelpro.com/

Location of Sqlite databases in OSX

Im learning Ruby on Rails 3 and would like to see the db structures created by various Scaffold commands in Sqlite3 in order to understand more the process.
In OSX Snow Leopard, entering:
which sqlite3
yields:
"/usr/local/bin/sqlite3"
However cant seem to find the databases! Pointing to that location merely yields the following error message:
connection failed. file is encrypted or is not a database
To view the dbs im using:
Navicat for Sqlite
anyone enlighten me where the dbs actually reside? "/usr/local/bin/sqlite3" seems to be an symlink to: /usr/local/Cellar/sqlite/3.7.10/bin/sqlite3s
SQLite is actually serverless, so the DB files by default reside in your rails directory.
For example:
/db/development.sqlite3
You can check where all your sqlite environment databases are on config/database.yml

Accessing SQLite3 directly?

I am stating out learning Ruby on Rails. For that I am using "Agile Web Development with Rails 4th edition book" which basically walks you through the creation of a sample project.
Even though I am getting the basics down from it I have failed to understand what I believe is a fundamental concept. Where exactly is the relational database and how can I access it directly?
If I was using PHP/MySQL I would go to phpmyadmin and could query the data directly.
How can achieve this with SQLite3?
I am using Linux (Ubuntu) and installed ror and sqlite with gem.
Thanks.
From your Rails root you can access the database command line directly with:
$ sqlite3 db/development.sqlite3
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
The SQLite3 database is stored in a file, usually located in the db/ folder. If you use Firefox, I recommend the SQLite Manager addon.
You can use other databases if you want to, see 3.3 Configuring a Database in the getting started guide for rails.

How to import existing ROR project?

I'm new to Ruby on Rails (PHP developer here) and I need to edit an existing ROR project. I've been using Aptana Studio for my PHP projects (switched to Zend after Aptana 2.0) but I've kept Aptana RadRails for my ruby projects.
So what I want to do is to get the ROR project from the server (it's hosted on some linux machine) and import it into RadRails for local development. I've downloaded the files from the server and imported them in a new RadRails ROR project but it doesn't work as intended. Is there anything else I should do ? I've read about 'freezing the gems', switching to production mode and dumping the database for a ROR project upon releasing. Are there some steps needed to undo those operations ?
UPDATE:
The problem that I'm having is that I get various errors when trying to visualize in the browser the pages for different controllers.
ActionController::InvalidAuthenticityToken in
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
OR
no such file to load -- xml
This error occurred while loading the following files:
hotels_pro
xml
This leads me to believe that (maybe) I haven't got all the files. On the other hand I have double-checked and I have all the files from the server.
Thanks,
A RoR application is more than just the sum of its source files. There's also the database, gems and a server which exist outside the project directory. Without knowing exactly what doesn't we can only speculate which is causing you problems. Being new to Rails, it's probably all of them. If after all this you're still not up and running a few rounds of "Google the Error" should fix you up.
You'll need to set these things up in your development environment before you can proceed. The following assumes you have a working ruby environment: rubygems installed with the rails, and rake gems. Note any commands and paths that follow are relative to the root of your rails project.
Database:
Start with editing config/databases.yml to find out which database your app will try to connect to. Change it if necessary so it names a local database. Create that database, if it doesn't exist with $rake db:create
If you need existing data to test with you can take a dump from your production database and import it into your working database. How to do this is dependent on the type of database in question. Otherwise you can run the migrations with $ rake db:migrate to produce your development database (assuming the previous developer designed the database with migrations.)
Gems:
Check the config/environment.rb, for your list of required gems. Install all these gems if they haven't been already.
If you're using Rails 2.1 or newer, you can streamline this process by ensuring that all gems are required using the newer config.gem 'this_gem' form instead of older require 'this_gem' declaration. Once all required gems are in this form, you can use $ rake gems:install && rake gems:build to ensure they're all installed.
Server:
Is pretty trivial, all rails instalations come with web brick which is fine for development. But mongrel is also suitable.
P.S. If you're not using some kind of revision control it's strongly advised to set something up before starting. It's not a requirement, but it will likely save your ass at some point.

Resources