From 13c33ef7de2f62354e874708b3a062aecf06d524 Mon Sep 17 00:00:00 2001 From: Carlos Donderis Date: Fri, 27 Feb 2015 15:47:54 +0900 Subject: [PATCH] changing links to use seo friendly urls --- app/app.rb | 2 ++ app/controllers/areas.rb | 3 ++- app/controllers/visions.rb | 1 + app/views/areas/_area_block.erb | 4 ++-- app/views/layouts/_landing_block.erb | 2 +- app/views/layouts/new_landing.erb | 2 +- app/views/maps/show.erb | 2 +- app/views/visions/show.erb | 4 ++-- db/schema.rb | 4 +++- 9 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/app.rb b/app/app.rb index 7300254..3c21527 100644 --- a/app/app.rb +++ b/app/app.rb @@ -71,7 +71,9 @@ class TokyoProject < Padrino::Application get '/sitemap', :provides => [:xml] do static_pages = [uri(url("/")), uri(url("/about")), uri(url(:areas, :index)), uri(url(:visions, :index))] areas = Area.scoped.collect{|area| uri url(:areas, :show, id: "#{area.id}")} + areas += Area.scoped.collect{|area| uri url(:areas, :show, id: "#{area.url_title}")} visions = Vision.scoped.collect{|vision| uri url(:visions, :show, id: "#{vision.id}")} + visions += Vision.scoped.collect{|vision| uri url(:visions, :show, id: "#{vision.url_title}")} posts = Post.scoped.collect{|post| uri url(:blog, :show, id: "#{post.id}")} @urls = static_pages + areas + visions + posts render 'layouts/sitemap' diff --git a/app/controllers/areas.rb b/app/controllers/areas.rb index 6f038d6..615ba08 100644 --- a/app/controllers/areas.rb +++ b/app/controllers/areas.rb @@ -16,7 +16,8 @@ get :show, :with => :id do key = "area_show_#{params[:id]}" cache(key, expires_in: (Padrino.env.to_s == "production" ? 3600 : 1)) do - @area = Area.find(params[:id]) + @area = Area.find(params[:id]) rescue nil + @area ||= Area.find_by_url_title(params[:id]) rescue nil content_for(:meta_description) { "#{@area.description}"} content_for(:title) { @area.name } @visions = @area.visions.find_all{|v| v.published_pictures.any?} diff --git a/app/controllers/visions.rb b/app/controllers/visions.rb index bd703bb..72d5952 100644 --- a/app/controllers/visions.rb +++ b/app/controllers/visions.rb @@ -20,6 +20,7 @@ cache(key, expires_in: (Padrino.env.to_s == "production" ? 3600 : 1)) do @vision = Vision.find(params[:id]) rescue nil + @vision ||= Vision.find_by_url_title(params[:id]) rescue nil content_for(:meta_description) { @vision.meta_description.present? ? @vision.meta_description : @vision.short_description} content_for(:meta_keywords) { @vision.meta_keywords} content_for(:title) { @vision.title } diff --git a/app/views/areas/_area_block.erb b/app/views/areas/_area_block.erb index 2f47c26..76fdbab 100644 --- a/app/views/areas/_area_block.erb +++ b/app/views/areas/_area_block.erb @@ -1,6 +1,6 @@
<% picture_url = vision.published_pictures.any? ? vision.published_pictures.first.medium : Vision::DEFAULT_MEDIUM_PICTURE_URL %> - <%= link_to(image_tag(picture_url), url(:areas, :show, :id => area.id))%> + <%= link_to(image_tag(picture_url), url(:areas, :show, :id => area.url_title))%>
-

<%= link_to(area.name, url(:areas, :show, :id => area.id)) %>

+

<%= link_to(area.name, url(:areas, :show, :id => area.url_title)) %>

<%= area.description %>

\ No newline at end of file diff --git a/app/views/layouts/_landing_block.erb b/app/views/layouts/_landing_block.erb index 1c20b29..79b6ce0 100644 --- a/app/views/layouts/_landing_block.erb +++ b/app/views/layouts/_landing_block.erb @@ -1,6 +1,6 @@
<% picture_url = vision.published_pictures.any? ? vision.published_pictures.first.medium : Vision::DEFAULT_MEDIUM_PICTURE_URL %> - <%= link_to(image_tag(picture_url), url(:visions, :show, :id => vision.id))%> + <%= link_to(image_tag(picture_url), url(:visions, :show, :id => vision.url_title))%>

<%= link_to(vision.title, url(:visions, :show, :id => vision.id)) %>

<%= vision.short_description %>

\ No newline at end of file diff --git a/app/views/layouts/new_landing.erb b/app/views/layouts/new_landing.erb index 4b8d6b4..a019ed8 100644 --- a/app/views/layouts/new_landing.erb +++ b/app/views/layouts/new_landing.erb @@ -72,7 +72,7 @@
<% @latest_visions.each_with_index do |vision, index| %>
-

<%= link_to(vision.title, url(:visions, :show, :id => vision.id)) %>

+

<%= link_to(vision.title, url(:visions, :show, :id => vision.url_title)) %>

diff --git a/app/views/maps/show.erb b/app/views/maps/show.erb index 8018946..56a10e6 100644 --- a/app/views/maps/show.erb +++ b/app/views/maps/show.erb @@ -3,7 +3,7 @@

<%=@vision.title%>

- Back to <%= link_to "normal view", url(:visions, :show, :id => @vision.id) %> + Back to <%= link_to "normal view", url(:visions, :show, :id => @vision.url_title) %>

<%= @vision.short_description %>

diff --git a/app/views/visions/show.erb b/app/views/visions/show.erb index b0019fc..81a97e3 100644 --- a/app/views/visions/show.erb +++ b/app/views/visions/show.erb @@ -3,7 +3,7 @@

<%=@vision.title%>

- See more visions for <%= link_to @vision.area.name, url(:areas, :show, :id => @vision.area) %> area + See more visions for <%= link_to @vision.area.name, url(:areas, :show, :id => @vision.area.url_title) %> area <%= link_to "(View on map)", url(:maps, :show, :id => @vision.id) if @vision.has_map_info?%>

<%= @vision.short_description %>

@@ -32,7 +32,7 @@
- <% vision_url = uri url(:visions, :show, id: "#{@vision.id}") %> + <% vision_url = uri url(:visions, :show, id: "#{@vision.url_title}") %>
diff --git a/db/schema.rb b/db/schema.rb index ed1fde5..f951221 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 11) do +ActiveRecord::Schema.define(:version => 13) do create_table "accounts", :force => true do |t| t.string "name" @@ -29,6 +29,7 @@ t.integer "ward_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "url_title" end create_table "pictures", :force => true do |t| @@ -66,6 +67,7 @@ t.string "wiki_url" t.string "meta_keywords" t.string "meta_description" + t.string "url_title" end create_table "wards", :force => true do |t|