This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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