Compare commits
3 Commits
9b03bbd714
...
2f05d48cd5
Author | SHA1 | Date | |
---|---|---|---|
2f05d48cd5 | |||
a7bd26864f | |||
2488d3073a |
@ -1,8 +1,8 @@
|
|||||||
class MoviesController < ApplicationController
|
class MoviesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@choices, @movies = ["Iron Man ⎊", "Batman 🦇", "Forrest Gump 🏃"], []
|
@choices, @movies = Movie.all, []
|
||||||
(0..15).each{ |num|
|
(0..15).each{ |num|
|
||||||
@movies.append(@choices.sample())
|
@movies.append(@choices.sample())
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
2
app/models/movie.rb
Normal file
2
app/models/movie.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class Movie < ApplicationRecord
|
||||||
|
end
|
@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<% @movies.each do |movie| %>
|
<% @movies.each do |movie| %>
|
||||||
<li><%= movie %></li>
|
<li><%= movie.title %> (<%= movie.rating %>, <%= movie.released_on %>): <%= number_to_currency(movie.total_gross, precision: 0) %>
|
||||||
|
<br /><i><%= movie.description %></i>
|
||||||
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
11
db/migrate/20230925181424_create_movies.rb
Normal file
11
db/migrate/20230925181424_create_movies.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class CreateMovies < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
create_table :movies do |t|
|
||||||
|
t.string :title
|
||||||
|
t.string :rating
|
||||||
|
t.decimal :total_gross
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
6
db/migrate/20230925183426_add_fields_to_movies.rb
Normal file
6
db/migrate/20230925183426_add_fields_to_movies.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class AddFieldsToMovies < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :movies, :description, :text
|
||||||
|
add_column :movies, :released_on, :date
|
||||||
|
end
|
||||||
|
end
|
24
db/schema.rb
generated
Normal file
24
db/schema.rb
generated
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# This file is the source Rails uses to define your schema when running `bin/rails
|
||||||
|
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
||||||
|
# be faster and is potentially less error prone than running all of your
|
||||||
|
# migrations from scratch. Old migrations may fail to apply correctly if those
|
||||||
|
# migrations use external dependencies or application code.
|
||||||
|
#
|
||||||
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema[7.0].define(version: 2023_09_25_183426) do
|
||||||
|
create_table "movies", force: :cascade do |t|
|
||||||
|
t.string "title"
|
||||||
|
t.string "rating"
|
||||||
|
t.decimal "total_gross"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.text "description"
|
||||||
|
t.date "released_on"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
11
test/fixtures/movies.yml
vendored
Normal file
11
test/fixtures/movies.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
title: MyString
|
||||||
|
rating: MyString
|
||||||
|
total_gross: 9.99
|
||||||
|
|
||||||
|
two:
|
||||||
|
title: MyString
|
||||||
|
rating: MyString
|
||||||
|
total_gross: 9.99
|
7
test/models/movie_test.rb
Normal file
7
test/models/movie_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class MovieTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user