Skip to content

Commit

Permalink
changing links to use seo friendly urls
Browse files Browse the repository at this point in the history
  • Loading branch information
CaDs committed Feb 27, 2015
1 parent 5fc3f65 commit 13c33ef
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/app.rb
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/areas.rb
Expand Up @@ -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?}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/visions.rb
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions app/views/areas/_area_block.erb
@@ -1,6 +1,6 @@
<div class="image">
<% 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))%>
</div>
<h2><%= link_to(area.name, url(:areas, :show, :id => area.id)) %></h2>
<h2><%= link_to(area.name, url(:areas, :show, :id => area.url_title)) %></h2>
<p><%= area.description %></p>
2 changes: 1 addition & 1 deletion app/views/layouts/_landing_block.erb
@@ -1,6 +1,6 @@
<div class="image">
<% 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))%>
</div>
<h2><%= link_to(vision.title, url(:visions, :show, :id => vision.id)) %></h2>
<p><%= vision.short_description %></p>
2 changes: 1 addition & 1 deletion app/views/layouts/new_landing.erb
Expand Up @@ -72,7 +72,7 @@
<br clear="all"/>
<% @latest_visions.each_with_index do |vision, index| %>
<div class="header" id="anchor_<%= vision.id %>">
<h3><%= link_to(vision.title, url(:visions, :show, :id => vision.id)) %></h3>
<h3><%= link_to(vision.title, url(:visions, :show, :id => vision.url_title)) %></h3>
</div>
<div class="gap gap-100" style="background-image:url(<%= vision.pictures.published.last.large%>);"></div>
<div class="content" id="anchor_<%= vision.id %>">
Expand Down
2 changes: 1 addition & 1 deletion app/views/maps/show.erb
Expand Up @@ -3,7 +3,7 @@
<div class="span12">
<h2><%=@vision.title%></h2>
<h4>
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) %>
</h4>
<h4 class="muted"><%= @vision.short_description %></h4>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/visions/show.erb
Expand Up @@ -3,7 +3,7 @@
<div class="span12">
<h2><%=@vision.title%></h2>
<h4>
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?%>
</h4>
<h4 class="muted"><%= @vision.short_description %></h4>
Expand Down Expand Up @@ -32,7 +32,7 @@
<a class="right carousel-control vision_link" href="#canvas" data-slide="next"></a>
</div>
<div>
<% vision_url = uri url(:visions, :show, id: "#{@vision.id}") %>
<% vision_url = uri url(:visions, :show, id: "#{@vision.url_title}") %>
<div id="fb" class="fb-like" data-href="<%= vision_url %>" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
<div id="gplus" class="g-plus" data-action="share" data-annotation="bubble" data-href="<%= vision_url %>"></div>
<a id = "twit" href='https://twitter.com/share' class='twitter-share-button' data-url="<%= vision_url %>" data-text='<%= "The Tokyo Project, 「#{@vision.title}」"%>'>Tweet</a>
Expand Down
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -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"
Expand All @@ -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|
Expand Down Expand Up @@ -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|
Expand Down

0 comments on commit 13c33ef

Please sign in to comment.