You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy bootstrap.min.css into app/assets/stylesheets directory
Copy bootstrap.min.js into app/assets/javascripts directory
Let's try it:
$ rails s
# Got to localhost:3000
# Should see default page
Add routes
Edit config/routes.rb
Movies::Application.routes.draw do
root 'movies#index'
end
Reload "localhost:3000" and review error message.
The error message says we need a controller, we do!
Generate controller:
$ rails generate controller movies
# Convention: controller names are plural and written in CamelCase.
# This will create an actual controller name that is in snake_case.
# if you used the wrong name and want to undo the controller generation use:
$ rails destroy controller movies
Reload "localhost:3000" and review error message.
The error message says we need an index method in our controller, let's make one!
Create index method
class MoviesController < ApplicationController
def index
end
end
Reload "localhost:3000" and review error message.
The error message says we have a missing template movies/index. We are getting there!
Create app/views/movies/index.html.erb
<h1>Rails Movie App</h1>
Reload "localhost:3000" - page should load!
Controller Instance Variables
Let's create some controller instance variables.
app/controllers/movies_controller.rb:
class MoviesController < ApplicationController
@@movies_db = [
{"title"=>"The Matrix", "year"=>"1999", "imdbID"=>"tt0133093", "type"=>"movie"},
{"title"=>"The Matrix Reloaded", "year"=>"2003", "imdbID"=>"tt0234215", "type"=>"movie"},
{"title"=>"The Matrix Revolutions", "year"=>"2003", "imdbID"=>"tt0242653", "type"=>"movie"}]
def index
@movies = @@movie_db
end
end