Skip to content

Commit

Permalink
Add scopes for video type, Refs #33
Browse files Browse the repository at this point in the history
  • Loading branch information
nunulong committed May 27, 2016
1 parent 96f5ab0 commit a835761
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class VideosController < ApplicationController
def index

if I18n.locale.to_s == "en"
@videos = Video.where(video_type: "Youtube")
@videos = Video.video_by_type("Youtube")
elsif I18n.locale.to_s == "zh-CN"
@videos = Video.where(video_type: "Youku")
@videos = Video.video_by_type("Youku")
end
end

Expand Down
6 changes: 6 additions & 0 deletions app/models/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class Video < ApplicationRecord
has_and_belongs_to_many :users
has_and_belongs_to_many :tags
# this is done before save or update

# scope :by_youtube, -> {where(video_type: "Youtube")}
# scope :by_youku, -> {where(video_type: "Youku")}
scope :video_by_type, ->(video_type) {where(video_type: video_type)}


before_save do
if self.summary_md_changed?
puts "convert md to html"
Expand Down

0 comments on commit a835761

Please sign in to comment.