Last active
December 18, 2015 13:53
-
-
Save xymbol/f7f86bc4694a00724675 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
validates_presence_of :locale | |
validates_inclusion_of :locale, in: %w(en es) | |
def self.with_locale(locale) | |
where locale: locale | |
end | |
end | |
class ApplicationController < ActionController::Base | |
before_action :set_locale | |
protected | |
def set_locale | |
I18n.locale = params[:locale] || I18n.default_locale | |
end | |
end | |
class PostsController < ApplicationController | |
def index | |
@posts = scope | |
end | |
def show | |
@post = scope.find params[:id] | |
end | |
private | |
def scope | |
Post.with_locale I18n.locale | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment