Skip to content

Commit 4ad4a68

Browse files
committed
Add user.id to lists
1 parent a134b68 commit 4ad4a68

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

app/controllers/lists_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def new
1414

1515
def create
1616
@list = List.new(list_params)
17+
@list.user = current_user.id
1718

1819
if @list.save
1920
redirect_to list_path(@list)
@@ -37,6 +38,6 @@ def set_list
3738
end
3839

3940
def list_params
40-
params.require(:list).permit(:name, :photo)
41+
params.require(:list).permit(:name, :photo, :user)
4142
end
4243
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUserToLists < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :lists, :user, :integer
4+
end
5+
end

db/movie_db_api_service.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ def call
1010

1111
all_movies = []
1212
movies["results"].each do |movie|
13-
the_movie = { title: movie["title"], overview: movie["overview"], poster_url: "https://image.tmdb.org/t/p/original#{movie["backdrop_path"]}", rating: movie["vote_average"].to_i }
14-
all_movies << { title: movie["title"], overview: movie["overview"], poster_url: "https://image.tmdb.org/t/p/original#{movie["backdrop_path"]}", rating: movie["vote_average"].to_i }
13+
all_movies << {
14+
title: movie["title"],
15+
overview: movie["overview"],
16+
poster_url: "https://image.tmdb.org/t/p/original#{movie["backdrop_path"]}",
17+
rating: movie["vote_average"].to_i
18+
}
1519
end
1620

1721
all_movies
1822
end
19-
2023
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2022_05_25_142349) do
13+
ActiveRecord::Schema.define(version: 2022_05_26_073949) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -57,6 +57,7 @@
5757
t.string "name"
5858
t.datetime "created_at", precision: 6, null: false
5959
t.datetime "updated_at", precision: 6, null: false
60+
t.integer "user"
6061
end
6162

6263
create_table "movies", force: :cascade do |t|

0 commit comments

Comments
 (0)