Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Last active August 29, 2015 14:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fliiiix/cd999777e97888bc5c6d to your computer and use it in GitHub Desktop.
#version 1
get "/:name/?" do |name|
url = Url.first(:nice => name)
halt 404 if url == nil
if url.post_id != nil
@post = Post.find(url.post_id)
elsif url.respond_to?(:music_post_id)
@post = MusicPost.find(url.music_post_id)
elsif url.respond_to?(:video_post_id)
@post = VideoPost.find(url.video_post_id)
end
halt 404 if @post == nil
halt 404 if !admin? && @post.publish == false
erb :index
end
#version 2
get "/:name/?" do |name|
url = Url.first(:nice => name)
halt 404 if url == nil
if url.post_id != nil
@post = Post.find(url.post_id)
end
if defined? url.music_post_id
puts url.music_post_id
@post = MusicPost.find(url.music_post_id)
end
if defined? url.video_post_id
@post = VideoPost.find(url.video_post_id)
end
halt 404 if @post == nil
halt 404 if !admin? && @post.publish == false
erb :index
end
#version 3
get "/:name/?" do |name|
url = Url.first(:nice => name)
halt 404 if url == nil
if url.post_id != nil
@post = Post.find(url.post_id)
end
begin
url.music_post_id
@post = MusicPost.find(url.music_post_id)
rescue Exception => e
puts "ex #{e}"
end
begin
url.video_post_id
@post = VideoPost.find(url.video_post_id)
rescue Exception => e
puts "ex #{e}"
end
halt 404 if @post == nil
halt 404 if !admin? && @post.publish == false
erb :index
end
#version 4
get "/:name/?" do |name|
@post = nil
url = Url.first(:nice => name)
halt 404 if url == nil
puts "url: #{url.inspect}"
if url.post_id != nil
@post = Post.find(url.post_id)
elsif url.respond_to?(:music_post_id)
@post = MusicPost.find(url.music_post_id)
elsif url.respond_to?(:video_post_id)
@post = VideoPost.find(url.video_post_id)
end
halt 404 if @post == nil
halt 404 if !admin? && @post.publish == false
erb :index
end
#version 5
get "/:name/?" do |name|
url = String.new
@post = nil
url = Url.first(:nice => name)
halt 404 if url == nil
puts "url: #{url.inspect}"
if url.post_id != nil
@post = Post.find(url.post_id)
end
if defined? url.music_post_id && url.music_post_id != nil
@post = MusicPost.find(url.music_post_id)
puts "hit music"
end
if defined? url.video_post_id && url.video_post_id != nil
@post = VideoPost.find(url.video_post_id)
puts "hit video"
end
puts "defined music: #{defined? url.music_post_id}"
puts "defined video: #{defined? url.video_post_id}"
puts "defined music inhalt: #{url.music_post_id.inspect}"
puts "defined video inhalt: #{url.video_post_id.inspect}"
halt 404 if @post == nil
halt 404 if !admin? && @post.publish == false
erb :index
end
#version 6
get "/:name/?" do |name|
@post = nil
url = Url.first(:nice => name)
halt 404 if url == nil
if url.post_id != nil
@post = Post.find(url.post_id)
end
begin
@post = MusicPost.find(url.music_post_id) if @post == nil
rescue Exception => e
end
begin
@post = VideoPost.find(url.video_post_id) if @post == nil
rescue Exception => e
end
halt 404 if @post == nil
halt 404 if !admin? && @post.publish == false
erb :index
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment