Skip to content

Instantly share code, notes, and snippets.

@jonpaul
Forked from bsodmike/public_controller.rb
Created October 28, 2011 18:25
Show Gist options
  • Save jonpaul/1322983 to your computer and use it in GitHub Desktop.
Save jonpaul/1322983 to your computer and use it in GitHub Desktop.
Render 404 via catch-all route in Rails 3.1
class CmsPageNotFound < StandardError; end
class PublicController < ApplicationController
rescue_from CmsPageNotFound do
render 'not_found', :status => :not_found and return false
end
def index
end
def show
@content_item = parse_path(params[:path])
raise CmsPageNotFound unless @content_item
end
private
def parse_path(path_parts)
# item = nil
# path = path_parts.split("/")
# if path.size == 1
# %w().include?path[0] ? item = true : item = false
# elsif path_parts.size >= 2
# end
# item
nil
end
end
match "*path" => 'public#show'
@bsodmike
Copy link

line 22 needs a correction if you plan to use this =)

elsif path.size >= 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment