Created
March 19, 2011 17:04
-
-
Save ravinggenius/877618 to your computer and use it in GitHub Desktop.
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
# The whole point of this file is to allow a site admin to specify what specific action OR page should be used for the home page. | |
class HomeController < ApplicationController | |
def index | |
# Setting[:site, :home_page] should return a string containing... | |
# a (url) path that corresponds to a specific node | |
# or | |
# a controller#action pair like what might be used for a route's :to option (action would likely be :index, but maybe not) | |
# or | |
# a controller#action#id triple which would allow actions (like :show) that require an id to be used | |
setting = Setting[:site, :home_page].split '#' | |
case setting.count | |
when 1 # show a specific node | |
# NodesController#show_human finds a node based on the path that was set when the node was created | |
# a path could be 'about' or 'about/when/i/was/a/boy' or the node's database id | |
params[:path] = setting.first | |
s_controller, s_action = :nodes, :show_human | |
when 2, 3 # show an arbitrary controller#action pair, with optional id | |
s_controller, s_action, params[:id] = setting | |
params.delete :id unless params[:id] | |
else | |
# this shouldn't happen... | |
# fall back to just listing nodes | |
s_controller, s_action = :nodes, :index | |
end | |
reply = "#{s_controller}_controller".classify.constantize.action(s_action).call(env) | |
status, response_headers, response_body = reply | |
# FIXME this is gross, but seems to work | |
# this is needed because status is 304 every other request. why? | |
if (200..299).include? status | |
render :text => response_body.body | |
else | |
head status | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment