diff --git a/lib/merged/engine.rb b/lib/merged/engine.rb index 31520df..60b5d37 100644 --- a/lib/merged/engine.rb +++ b/lib/merged/engine.rb @@ -42,6 +42,7 @@ module ActionDispatch::Routing # post /form for form processing # get /news/:id for any news posts # get /:id for any pages + # redirects from any renamed page # root to /index unless options[:root] == false # mount the engine (make editing possible) unless production # or oprions[:production] == true (not recommended) @@ -51,6 +52,15 @@ module ActionDispatch::Routing root "merged/view#page" , id: 'index' end + Merged::Page.all.each do |page| + next unless page.redirects + page.redirects.split.each do |old| + next if old == page.name + puts "redirect #{old} to #{page.name}" + get "/#{old}" => redirect("/#{page.name}") + end + end + post "/form" , to: "merged/form#post" , as: :post_form get "/news/:id" , to: "merged/view#page" , id: :id , as: :view_blog get ":id" , to: "merged/view#page" , id: :id , as: :view_page