Permalink
Browse files

Adding locale sentitive links to change locale

  • Loading branch information...
akitaonrails committed Jul 14, 2012
1 parent 5555af3 commit 53e6299e60b05f9d9cc350ce3bb994c698459646
Showing with 16 additions and 2 deletions.
  1. +1 −1 app/controllers/articles_controller.rb
  2. +12 −0 app/helpers/application_helper.rb
  3. +3 −1 app/views/articles/show.html.erb
@@ -1,6 +1,6 @@
class ArticlesController < ApplicationController
def show
@article = Article.find(params[:id])
- @body_html = RDiscount.new(@article.body || "").to_html
+ @body_html = RDiscount.new(@article.body || "").to_html.html_safe
end
end
@@ -1,2 +1,14 @@
module ApplicationHelper
+ def language_links
+ links = []
+ I18n.available_locales.each do |locale|
+ locale_key = "translation.#{locale}"
+ if locale == I18n.locale
+ links << I18n.t(locale_key)
+ else
+ links << link_to(I18n.t(locale_key), url_for(locale: locale.to_s))
+ end
+ end
+ content_tag(:p, links.join(" | ").html_safe)
+ end
end
@@ -1,3 +1,5 @@
<h1><%= @article.title %></h1>
-<%=raw @article.body %>
+<%= @body_html %>
+
+<%= language_links %>

0 comments on commit 53e6299

Please sign in to comment.