How can I simplify my nested sinatra routes?

Posted by yaya3 on Stack Overflow See other posts from Stack Overflow or by yaya3
Published on 2010-06-07T14:28:30Z Indexed on 2010/06/07 15:52 UTC
Read the original article Hit count: 396

Filed under:
|
|

I require nested subdirectories in my sinatra app, how can I simplify this repetitive code?

# ------------- SUB1 --------------
get "/:theme/:sub1/?" do
    haml :"pages/#{params[:theme]}/#{params[:sub1]}/index"
end

# ------------- SUB2 --------------
get "/:theme/:sub1/:sub2/?" do
    haml :"pages/#{params[:theme]}/#{params[:sub1]}/#{params[:sub2]}/index"
end

# ------------- SUB3 --------------
get "/:theme/:sub1/:sub2/:sub3/?" do
    haml :"pages/#{params[:theme]}/#{params[:sub1]}/#{params[:sub2]}/#{params[:sub3]}/index"
end

# ------------- SUB4 --------------
get "/:theme/:sub1/:sub2/:sub3/:sub4/?" do
    haml :"pages/#{params[:theme]}/#{params[:sub1]}/#{params[:sub2]}/#{params[:sub3]}/#{params[:sub4]}/index"
end

© Stack Overflow or respective owner

Related posts about ruby

Related posts about routing