Skip to content

Instantly share code, notes, and snippets.

@parndt
Created May 11, 2010 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parndt/396780 to your computer and use it in GitHub Desktop.
Save parndt/396780 to your computer and use it in GitHub Desktop.
<div id='editor_switch'>
<%
if admin?
(r = ::ActionController::TestRequest.new(request.env)).path = (request.request_uri.to_s.match(/\/admin(.*)\/edit/)[1] rescue root_url)
public_route = ((c = ActionController::Routing::Routes.recognize(r)).present? and c != ApplicationController) ? r.path : root_url rescue root_url
else
if @page.present? and !@page.home?
editor_route = edit_admin_page_url(@page)
else
editor_route = (request.request_uri.to_s == '/') ? admin_root_url : "/admin#{request.request_uri}/edit"
end
end
-%>
<%=
link_to_if(admin?, "Switch to live view", public_route) do
link_to "Switch to editor view", editor_route
end
-%>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment