RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

ActiveRecord#Enum translation

https://github.com/shlima/translate_enum

Lightweight gem to handle your ActiveRecord models enum translations.

class Post < ActiveRecord::Base
  enum status: { published: 0, archive: 1 }
  translate_enum :status
end

Use cases

Post.translated_status(:published) #=> "Was published"
Post.translated_statuses => #=> Array
@post = Post.new(status: :published)
@post.translated_status #=> "Was published"

Form

statuses = f.object.translated_statuses.map { |translation, k, _v| [translation, k] }
f.select :status, options_for_select(statuses)

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in