Why won't my tutorial rails app work? - ruby-on-rails

I'm learning rails with "agile web development with rails (3rd edition)" and I've gotten to the point where I'm supposed to make the depot app.
I have created the depot app, and I've added the script/generate files. I've raked the db. For some reason, no tables where created in the migration and upon running this command:
depot> sqlite3 db/development.sqlite3 "select version from schema_migrations"
I get nothing. Then when running localhost in my browser, instead of getting what I'm supposed to, I get the standard welcome to rails page.
Any advice?
Resolved:
It's always the simple things. Had to direct to localhost:3000/products instead of just to localhost:3000 - wasn't aware of this. Thanks!

There is a number of possibilities here, firstly, judging by the fact you can see the standard "Welcome to Rails" page you haven't deleted public/index.html - you should do this so that Rails can route to the root /
Secondly, if your migrations are running correctly you should have a schema.rb file in ./db with the instructions for each table, if not then something is failing there.
I have not read the 'Agile web development with Rails" book but I am assuming it was written before the release of Rails 3, which means your app does not use Bundler for gem dependency management so it might be worth checking that sqlite3 gem is installed. You can check this with gem list sqlite if you don't see something like "sqlite3-ruby (1.3.2)" then you need to install it.
Lastly, check the log files in ./log/

Well I guess you've created multiple migrations by now so try typing rake db:migrate at the command line and let use know what it says?

Related

What should I know before changing my development database?

Since I learned Rails from Micheal Hartl's tutorial, all of my apps are set up to use SQLite3 in development, but Postgresql in production. This is causing problems with searches that work in development but not in production. From other Stack overflow questions, I've learned that using different databases in different environments is a bad idea.
I think that my best solution is to change the development database to Postgresql. But I'm sure that it's not as simple as adjusting the db name in my gemfile. What other changes will I need to make? What are some potential side effects that I should be aware of?
Thank you in advance for any insight.
You can do it two ways.
First Way :
Below are steps you can follow to convert sqlite to postgres.
Install postgres.
Change your Gemfile in your rails app and add PG gem.
Run bundle install.
Change the database.yml file to use postgres.
Run rake db:setup followed by rake db:migrate.
Everything should work as expected, Because with rake db:setup and rake db:migrate you will get identical database as before.
Second Way :
Now rails also provide way to directly change DB from one DB to another, You can check here.
Just use below command and you are done.
bin/rails db:system:change --to=postgresql
Copy Data as well :
If you want to copy data as well you can use yaml_db gem.

Trying to Execute Ruby Code for the first time.

Project:
https://github.com/jmopr/job-hunter
Background:
Took only 2 intro course on Java 7 years ago.
So I was browsing GitHub and ran across this nifty project that deals with scraping & applying for jobs on indeed.com.
The question is, how do you run it? Here is what I tried to do:
Tried to execute applier.ru I figured I was doing something wrong after getting:
/home/shap/Desktop/job-hunter-master/applier.rb:19:in initialize': uninitialized constant JobApplier::Job (NameError)
from /home/shap/Desktop/job-hunter-master/applier.rb:169:innew'
from /home/shap/Desktop/job-hunter-master/applier.rb:169:in `'
Something was missing, so looking around I found the bin folder and tried executing /bin/setup.ru but i ran into this error:
== Preparing database ==
/var/lib/gems/2.3.0/gems/railties-4.2.5.1/lib/rails/application/configuration.rb:110:in database_configuration': Cannot loadRails.application.database_configuration`:
Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
Are we supposed to generate our own database file? how would we do that?
Any help or even a push in the right path is deeply appreciated.
You are supposed to generate your own database configuration. It should be stored at config/database.yml. It's a file that specify where's your db server, what's the name of the database and what should be the credentials to access it. Google "rails database.yml example".
Once you have that, creating your actual database is as easy as running these commands
rake db:create
rake db:migrate
There may be many-many other different obstacles on your journey of making this application run. Things that are obvious to rails devs, but arcane to total strangers. I suggest finding and completing a ruby on rails tutorial.
This is ruby on rails project,
after checkout you need install all required dependencies, with command
bundle exec install
Run project you can with command
./bin/rails server
If project is started successful, you can access it with browser using address http://localhost:3000
more about rails you can find there http://guides.rubyonrails.org/getting_started.html
http://guides.rubyonrails.org/getting_started.html

Cannot deploy with Passenger

I'm trying to deploy my first app with rails. I'm unable to deploy it, and I'm unhappy because the framework itself allowed me to develop really quickly the application, but I've only two days to make the deployment work :-(
I've installed and configured passenger following a tutorial (i'm using RVM).
When I access the page I have the following error page: traceback here (posted on pastebin to keep this post clear).
What is wrong?
i just uploaded the whole project on the production server, ran bundle install, rake db:create rake db:migrate and rake db:seed. Am I missing some step?
Why it doesn't run?
Developed using Rails 3.2.3 with Ruby 1.9.3.
Please help me to get it running.
Thanks,
Alex.
I have very little information about your problem but I have and idea what is going on. Check your belongs_to association in your event model if there is a class parameter replace it with class_name.

how to re-initialize a ruby on rails project

I've just been given a folder containing everything in a ruby on rails project that was developed 2 years ago. The folder doesn't contain a sqlite3 file however, so I am unable to view the database and I currently don't know how to run the application on my local computer.
What are the steps to re-starting a previously developed project so that further development can be done to it?
Thanks!
Owwwwww that is hard.
I see two main problems: gem dependencies and the database.
Gem dependencies are now cleanly managed with bundler, but two years ago that was not the case.
Getting all the gems you need for your project together will be the hardest part (depending on the size of the project).
Gem dependencies
Previously gems had to be defined in config/environment.rb, but actually require could be scattered all over the app, and depending on the discipline of the original developers, I guess no versions were specified. So it will be hard to compose a set of working gems, since a lot of gems change between versions.
In config/environment.rb you will also find the rails version.
Use rvm and a clean gemset. If the rails version is something 2.3.x, you could start using bundler.
Database
If you find a config/database.yml: then you know which type of database was expected. Adapt it to connect to your database (of the same type). If there is no such thing, start off with sqlite3, as it will cope with most simple cases (it will get you started).
The simplest way to get the database up and running is
rake db:create
rake db:setup
This will create an empty database (from your configuration), and then load the schema and the seeds.
Next steps
get the tests running (hopefully there are any)
consider upgrading to rails 3
Hope this helps.
First you'll need a config/database.yml file that defines how Rails connects to your database. If that's already in there, hopefully it's not in your versioning system :)
Second, you'll need to create the databases. You can do that with rake db:create.
Third, you will need to load the database schema. DO NOT do rake db:migrate as Dave mentioned in the comment above. This is not the recommend way to load the schema since it's slower and may not accurately represent the schema. Instead, use rake db:schema:load.

Ruby on Rails newbie: how to get decent error reporting?

So today I've been working with RoR for the first time using the book 'Rails for PHP developers'. I'm following the tutorial in there.
I created a project, with a model Subscriber and a controller Subscribers, which has a method create. Then I ran ruby script/server to launch Mongrel.
Now, the book says that if I go to http://localhost:3000/subscribers/create I should get an error because there's no template associated (yet) for this action. The book shows this error message:
Template missing
Missing template subscribers/create.html.erb in view path /Users/derek/work/newsletter/app/views
A nice descriptive error message, really helpful. But the error I get is:
We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.
That error is not helpful at all. I suspect it has to do with the fact that the book uses WEBrick, and I use Mongrel. But I assume it should be possible to get more descriptive errors, right? It seems quite painful to develop with errors like this.
It looks like some of your Rails install is semi borked. You might be missing the mysql gem or might not have the mysql ActiveRecord adaptor configured correctly.
Use gem list to see the gems you have installed
$ sudo gem list
you can use the gem install command to install or update gems
$ sudo gem install rails mysql
You usually want to install gems with sudo (as root) so all users can use them ( like apache or www-data)
Im sorry your first try at Rails hasn't gone smoothly, trust me it is an extremely powerful framework. Strick with it!
You probably forgot to setup the database. You can check log/development.log for further details.
you only get the first message if you are running in development mode.

Resources