ActiveRecord::StatementInvalid after laptop re-image - ruby-on-rails

I have run my first scaffold command to see if all is well, after the book purchase agile web development with rails.
rails generate scaffold product name:string
Upon loading WEBrick, I see the following error.
ActiveRecord::StatementInvalid in ProductsController#index
Debugging steps carried out on my own:
db migration looks well formed (although who am I to review?)
loaded sqlite3 shell and cannot find the products table
gem file contains a gem 'sqlite3' line
Really new to Rails and have tried to solve this problem myself and struggling to connect the dots.
Any advice or support would be appreciated.

Run rake db:migrate after generating the scaffold.

Related

How to run migrations from a gem

I have a gem installed in my rails app, and it has some migrations in
/db/migrate
how can I run them?
I've tried running
bundle exec rails g gem-name:install
but I get an error saying could not find generator gem-name:install.
I've run up against this problem with 3 different Gems this morning. What am I missing?
Old question, so sorry for the bump, but you were actually pretty dang close.
the correct command would be rails gem_name:install:migrations

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

Gem seems to affect other rails project of the same name

I created a rails project MyProject and tried to set up Devise in it (using this tutorial). After I did some Devise stuff I could not scaffold User anymore, I ran into an error as shown below. So I wanted to start over, renamed the project to MyProject-Devise and created a new project MyProject to create User first and then do my Devise stuff. Now in my new project of the same name, when I run
rails generate scaffold user name:string email:string
I run into the same error. If I create a new app with another name, I can scaffold the user with the same command. So I guess it must be the same name thing.
Any ideas why this happens? How to get rid of the error or how to properly start the project over again?
This is the error:
/Users/luke/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/inflector/methods.rb:238:in `const_get': uninitialized constant User (NameError)
Full error here: http://pastebin.com/KFh4U6aS
It looks like you might not be using Bundler. The tutorial you linked to had you create a Gemfile but didn't tell you to run bundle or bundle exec. Without Bundler you may be using a Devise installed directly into your Ruby's gems.
I suspect if you run the rails generate command with bundle exec you may have different results.
bundle exec rails generate scaffold user name:string email:string

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.

Why won't my tutorial rails app work?

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?

Resources