Skip to content

Commit

Permalink
update media feed with anonymous files
Browse files Browse the repository at this point in the history
. fix some migrations
  • Loading branch information
pavelz committed Dec 26, 2019
1 parent 23bbad0 commit 1258742
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ def index
@photos = Photo.all
end

photos = current_user.photos rescue Photo.where(user: nil).order("created_at desc")
videos = current_user.videos rescue Video.where(user: nil).order("created_at desc")
photos = nil
videos = nil
if current_user != nil
photos = Photo.where("user_id = ? or user_id is NULL", current_user.id)
videos = Video.where("user_id = ? or user_id is NULL", current_user.id)
else
photos = Photo.where(user: nil).order("created_at desc")
videos = Video.where(user: nil).order("created_at desc")
end


@feed = [photos, videos].flatten(1).sort_by{|a| a.created_at}.reverse()[0..MAX_FEED]
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20190509090818_create_photos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreatePhotos < ActiveRecord::Migration[5.2]
def change
create_table :photos do |t|
t.string :name
t.string :user_id
t.integer :user_id

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20190628140445_create_videos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreateVideos < ActiveRecord::Migration[5.2]
def change
create_table :videos do |t|
t.string :name
t.string :user_id
t.integer :user_id

t.timestamps
end
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

create_table "photos", force: :cascade do |t|
t.string "name"
t.string "user_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "image_data"
Expand All @@ -50,7 +50,7 @@

create_table "videos", force: :cascade do |t|
t.string "name"
t.string "user_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "video_data"
Expand Down

0 comments on commit 1258742

Please sign in to comment.