Skip to content
Browse files

Adding support to ActiveAdmin with Globalize3 integration

  • Loading branch information...
1 parent 0ff7071 commit 5555af3d990f0d378fe2409a90657b45457b0425 @akitaonrails committed Jul 14, 2012
View
3 Gemfile
@@ -11,6 +11,7 @@ gem 'devise'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
+ gem 'jquery-ui-rails'
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
@@ -25,6 +26,8 @@ gem 'rails-translate-routes'
gem 'globalize3'
gem 'friendly_id'
gem 'rdiscount'
+gem 'activeadmin'
+gem 'ActiveAdmin-Globalize3-inputs'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
42 Gemfile.lock
@@ -1,6 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
+ ActiveAdmin-Globalize3-inputs (0.0.1)
+ activeadmin
+ globalize3
actionmailer (3.2.6)
actionpack (= 3.2.6)
mail (~> 2.4.4)
@@ -14,6 +17,17 @@ GEM
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
+ activeadmin (0.4.4)
+ bourbon (>= 1.0.0)
+ devise (>= 1.1.2)
+ fastercsv
+ formtastic (~> 2.1.1)
+ inherited_resources (>= 1.3.1)
+ jquery-rails (>= 1.0.0)
+ kaminari (>= 0.13.0)
+ meta_search (>= 0.9.2)
+ rails (>= 3.0.0)
+ sass (>= 3.1.0)
activemodel (3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
@@ -30,6 +44,8 @@ GEM
multi_json (~> 1.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
+ bourbon (2.1.0)
+ sass (>= 3.1)
builder (3.0.0)
coderay (1.0.6)
coffee-rails (3.2.2)
@@ -48,29 +64,50 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ fastercsv (1.5.5)
+ formtastic (2.1.1)
+ actionpack (~> 3.0)
friendly_id (4.0.7)
globalize3 (0.2.0)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
paper_trail (~> 2)
+ has_scope (0.5.1)
hike (1.2.1)
i18n (0.6.0)
+ inherited_resources (1.3.1)
+ has_scope (~> 0.5.0)
+ responders (~> 0.6)
journey (1.0.4)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
+ jquery-ui-rails (1.0.0)
+ jquery-rails
+ railties (>= 3.1.0)
json (1.7.3)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ meta_search (1.1.3)
+ actionpack (~> 3.1)
+ activerecord (~> 3.1)
+ activesupport (~> 3.1)
+ polyamorous (~> 0.5.0)
method_source (0.7.1)
mime-types (1.19)
multi_json (1.3.6)
orm_adapter (0.3.0)
paper_trail (2.6.3)
activerecord (~> 3.0)
railties (~> 3.0)
+ polyamorous (0.5.0)
+ activerecord (~> 3.0)
polyglot (0.3.3)
pry (0.9.9.6)
coderay (~> 1.0.5)
@@ -106,6 +143,8 @@ GEM
rdiscount (1.6.8)
rdoc (3.12)
json (~> 1.4)
+ responders (0.9.1)
+ railties (~> 3.1)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
@@ -146,11 +185,14 @@ PLATFORMS
ruby
DEPENDENCIES
+ ActiveAdmin-Globalize3-inputs
+ activeadmin
coffee-rails (~> 3.2.1)
devise
friendly_id
globalize3
jquery-rails
+ jquery-ui-rails
pry-rails
rails (= 3.2.6)
rails-translate-routes
View
23 app/admin/articles.rb
@@ -0,0 +1,23 @@
+ActiveAdmin.register Article do
+ index do
+ column :id
+ column :slug
+ column :title
+
+ default_actions
+ end
+
+ form do |f|
+ f.input :slug
+ f.globalize_inputs :translations do |lf|
+ lf.inputs do
+ lf.input :title
+ lf.input :body
+
+ lf.input :locale, :as => :hidden
+ end
+ end
+
+ f.buttons
+ end
+end
View
44 app/admin/dashboards.rb
@@ -0,0 +1,44 @@
+ActiveAdmin::Dashboards.build do
+
+ # Define your dashboard sections here. Each block will be
+ # rendered on the dashboard in the context of the view. So just
+ # return the content which you would like to display.
+
+ # == Simple Dashboard Section
+ # Here is an example of a simple dashboard section
+ #
+ # section "Recent Posts" do
+ # ul do
+ # Post.recent(5).collect do |post|
+ # li link_to(post.title, admin_post_path(post))
+ # end
+ # end
+ # end
+
+ # == Render Partial Section
+ # The block is rendered within the context of the view, so you can
+ # easily render a partial rather than build content in ruby.
+ #
+ # section "Recent Posts" do
+ # div do
+ # render 'recent_posts' # => this will render /app/views/admin/dashboard/_recent_posts.html.erb
+ # end
+ # end
+
+ # == Section Ordering
+ # The dashboard sections are ordered by a given priority from top left to
+ # bottom right. The default priority is 10. By giving a section numerically lower
+ # priority it will be sorted higher. For example:
+ #
+ # section "Recent Posts", :priority => 10
+ # section "Recent User", :priority => 1
+ #
+ # Will render the "Recent Users" then the "Recent Posts" sections on the dashboard.
+
+ # == Conditionally Display
+ # Provide a method name or Proc object to conditionally render a section at run time.
+ #
+ # section "Membership Summary", :if => :memberships_enabled?
+ # section "Membership Summary", :if => Proc.new { current_admin_user.account.memberships.any? }
+
+end
View
2 app/assets/javascripts/active_admin.js
@@ -0,0 +1,2 @@
+//= require active_admin/base
+//= require jquery.ui.tabs
View
1 app/assets/javascripts/application.js
@@ -12,4 +12,3 @@
//
//= require jquery
//= require jquery_ujs
-//= require_tree .
View
7 app/assets/stylesheets/active_admin.css.scss
@@ -0,0 +1,7 @@
+// Active Admin CSS Styles
+@import "active_admin/mixins";
+@import "active_admin/base";
+@import "jquery.ui.tabs";
+
+// To customize the Active Admin interfaces, add your
+// styles here:
View
1 app/assets/stylesheets/application.css
@@ -9,5 +9,4 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
- *= require_tree .
*/
View
11 app/models/admin_user.rb
@@ -0,0 +1,11 @@
+class AdminUser < ActiveRecord::Base
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :confirmable,
+ # :lockable, :timeoutable and :omniauthable
+ devise :database_authenticatable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :email, :password, :password_confirmation, :remember_me
+ # attr_accessible :title, :body
+end
View
5 app/models/article.rb
@@ -1,12 +1,13 @@
class Article < ActiveRecord::Base
- attr_accessible :body, :slug, :title, :locale
+ attr_accessible :body, :slug, :title, :locale, :translations_attributes
extend FriendlyId
friendly_id :title, use: :slugged
translates :title, :body
+ accepts_nested_attributes_for :translations
class Translation
- attr_accessible :locale
+ attr_accessible :locale, :title, :body
end
private
View
1 config/application.rb
@@ -31,6 +31,7 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ config.i18n.available_locales = [:en, :"pt-BR"]
config.i18n.default_locale = :"pt-BR"
# Configure the default encoding used in templates for Ruby 1.9.
View
129 config/initializers/active_admin.rb
@@ -0,0 +1,129 @@
+ActiveAdmin.setup do |config|
+
+ # == Site Title
+ #
+ # Set the title that is displayed on the main layout
+ # for each of the active admin pages.
+ #
+ config.site_title = "I18n Demo"
+
+ # Set the link url for the title. For example, to take
+ # users to your main site. Defaults to no link.
+ #
+ # config.site_title_link = "/"
+
+ # Set an optional image to be displayed for the header
+ # instead of a string (overrides :site_title)
+ #
+ # Note: Recommended image height is 21px to properly fit in the header
+ #
+ # config.site_title_image = "/images/logo.png"
+
+ # == Default Namespace
+ #
+ # Set the default namespace each administration resource
+ # will be added to.
+ #
+ # eg:
+ # config.default_namespace = :hello_world
+ #
+ # This will create resources in the HelloWorld module and
+ # will namespace routes to /hello_world/*
+ #
+ # To set no namespace by default, use:
+ # config.default_namespace = false
+ #
+ # Default:
+ # config.default_namespace = :admin
+ #
+ # You can customize the settings for each namespace by using
+ # a namespace block. For example, to change the site title
+ # within a namespace:
+ #
+ # config.namespace :admin do |admin|
+ # admin.site_title = "Custom Admin Title"
+ # end
+ #
+ # This will ONLY change the title for the admin section. Other
+ # namespaces will continue to use the main "site_title" configuration.
+
+ # == User Authentication
+ #
+ # Active Admin will automatically call an authentication
+ # method in a before filter of all controller actions to
+ # ensure that there is a currently logged in admin user.
+ #
+ # This setting changes the method which Active Admin calls
+ # within the controller.
+ config.authentication_method = :authenticate_admin_user!
+
+
+ # == Current User
+ #
+ # Active Admin will associate actions with the current
+ # user performing them.
+ #
+ # This setting changes the method which Active Admin calls
+ # to return the currently logged in user.
+ config.current_user_method = :current_admin_user
+
+
+ # == Logging Out
+ #
+ # Active Admin displays a logout link on each screen. These
+ # settings configure the location and method used for the link.
+ #
+ # This setting changes the path where the link points to. If it's
+ # a string, the strings is used as the path. If it's a Symbol, we
+ # will call the method to return the path.
+ #
+ # Default:
+ config.logout_link_path = :destroy_admin_user_session_path
+
+ # This setting changes the http method used when rendering the
+ # link. For example :get, :delete, :put, etc..
+ #
+ # Default:
+ # config.logout_link_method = :get
+
+
+ # == Admin Comments
+ #
+ # Admin comments allow you to add comments to any model for admin use.
+ # Admin comments are enabled by default.
+ #
+ # Default:
+ # config.allow_comments = true
+ #
+ # You can turn them on and off for any given namespace by using a
+ # namespace config block.
+ #
+ # Eg:
+ # config.namespace :without_comments do |without_comments|
+ # without_comments.allow_comments = false
+ # end
+
+
+ # == Controller Filters
+ #
+ # You can add before, after and around filters to all of your
+ # Active Admin resources from here.
+ #
+ # config.before_filter :do_something_awesome
+
+
+ # == Register Stylesheets & Javascripts
+ #
+ # We recommend using the built in Active Admin layout and loading
+ # up your own stylesheets / javascripts to customize the look
+ # and feel.
+ #
+ # To load a stylesheet:
+ # config.register_stylesheet 'my_stylesheet.css'
+ #
+ # You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
+ # config.register_stylesheet 'my_print_stylesheet.css', :media => :print
+ #
+ # To load a javascript file:
+ # config.register_javascript 'my_javascript.js'
+end
View
3 config/locales/en.yml
@@ -3,3 +3,6 @@
en:
hello: "Hello world"
+ translation:
+ en: English
+ pt-BR: Portuguese
View
4 config/locales/pt-BR.yml
@@ -1,3 +1,5 @@
pt-BR:
hello: Olá Mundo
-
+ translation:
+ en: Inglês
+ pt-BR: Português
View
6 config/routes.rb
@@ -11,3 +11,9 @@
'config/locales/routes.yml', {
prefix_on_default_locale: true,
keep_untranslated_routes: true })
+
+I18nDemo::Application.routes.draw do
+ ActiveAdmin.routes(self)
+
+ devise_for :admin_users, ActiveAdmin::Devise.config
+end
View
17 db/migrate/20120713174528_create_admin_notes.rb
@@ -0,0 +1,17 @@
+class CreateAdminNotes < ActiveRecord::Migration
+ def self.up
+ create_table :admin_notes do |t|
+ t.string :resource_id, :null => false
+ t.string :resource_type, :null => false
+ t.references :admin_user, :polymorphic => true
+ t.text :body
+ t.timestamps
+ end
+ add_index :admin_notes, [:resource_type, :resource_id]
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
+ end
+
+ def self.down
+ drop_table :admin_notes
+ end
+end
View
25 db/migrate/20120713174529_move_admin_notes_to_comments.rb
@@ -0,0 +1,25 @@
+class MoveAdminNotesToComments < ActiveRecord::Migration
+ def self.up
+ remove_index :admin_notes, [:admin_user_type, :admin_user_id]
+ rename_table :admin_notes, :active_admin_comments
+ rename_column :active_admin_comments, :admin_user_type, :author_type
+ rename_column :active_admin_comments, :admin_user_id, :author_id
+ add_column :active_admin_comments, :namespace, :string
+ add_index :active_admin_comments, [:namespace]
+ add_index :active_admin_comments, [:author_type, :author_id]
+
+ # Update all the existing comments to the default namespace
+ say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
+ execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
+ end
+
+ def self.down
+ remove_index :active_admin_comments, :column => [:author_type, :author_id]
+ remove_index :active_admin_comments, :column => [:namespace]
+ remove_column :active_admin_comments, :namespace
+ rename_column :active_admin_comments, :author_id, :admin_user_id
+ rename_column :active_admin_comments, :author_type, :admin_user_type
+ rename_table :active_admin_comments, :admin_notes
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
+ end
+end
View
49 db/migrate/20120713204524_devise_create_admin_users.rb
@@ -0,0 +1,49 @@
+class DeviseCreateAdminUsers < ActiveRecord::Migration
+ def change
+ create_table(:admin_users) do |t|
+ ## Database authenticatable
+ t.string :email, :null => false, :default => ""
+ t.string :encrypted_password, :null => false, :default => ""
+
+ ## Recoverable
+ t.string :reset_password_token
+ t.datetime :reset_password_sent_at
+
+ ## Rememberable
+ t.datetime :remember_created_at
+
+ ## Trackable
+ t.integer :sign_in_count, :default => 0
+ t.datetime :current_sign_in_at
+ t.datetime :last_sign_in_at
+ t.string :current_sign_in_ip
+ t.string :last_sign_in_ip
+
+ ## Confirmable
+ # t.string :confirmation_token
+ # t.datetime :confirmed_at
+ # t.datetime :confirmation_sent_at
+ # t.string :unconfirmed_email # Only if using reconfirmable
+
+ ## Lockable
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
+ # t.datetime :locked_at
+
+ ## Token authenticatable
+ # t.string :authentication_token
+
+
+ t.timestamps
+ end
+
+ # Create a default user
+ AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') unless Rails.env.production?
+
+ add_index :admin_users, :email, :unique => true
+ add_index :admin_users, :reset_password_token, :unique => true
+ # add_index :admin_users, :confirmation_token, :unique => true
+ # add_index :admin_users, :unlock_token, :unique => true
+ # add_index :admin_users, :authentication_token, :unique => true
+ end
+end
View
35 db/schema.rb
@@ -11,7 +11,40 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120713201558) do
+ActiveRecord::Schema.define(:version => 20120713204524) do
+
+ create_table "active_admin_comments", :force => true do |t|
+ t.string "resource_id", :null => false
+ t.string "resource_type", :null => false
+ t.integer "author_id"
+ t.string "author_type"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "namespace"
+ end
+
+ add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id"
+ add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
+ add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id"
+
+ create_table "admin_users", :force => true do |t|
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :default => "", :null => false
+ t.string "reset_password_token"
+ t.datetime "reset_password_sent_at"
+ t.datetime "remember_created_at"
+ t.integer "sign_in_count", :default => 0
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
+ add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
create_table "article_translations", :force => true do |t|
t.integer "article_id"
View
5 spec/models/admin_user_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe AdminUser do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 5555af3

Please sign in to comment.
Something went wrong with that request. Please try again.