Create Beautiful Administration Interfaces with Active Admin

Create Beautiful Administration Interfaces with Active Admin

Tutorial Details
  • Difficulty: Medium
  • Framework: RoR
  • Estimated Completion Time: 1 hour

Every web developer knows that creating an administration interface for their projects is an incredibly tedious task. Luckily, there are tools that make this task considerably simpler. In this tutorial, I’ll show you how to use Active Admin, a recently launched administration framework for Ruby on Rails applications.

You can use Active Admin to add an administration interface to your current project, or you can even use it to create a complete web application from scratch – quickly and easily.

Today, we’ll be doing the latter, by creating a fairly simple project management system. It might sound like quite a bit of work, but Active Admin will do the bulk of the work for us!


Step 1 – Set up the Development Environment

I’m going to assume you have some previous Ruby on Rails knowledge, especially involving model validations, since the rest of the application interface is going to be taken care of by Active Admin. Apart from that, you should have a development environment for Ruby on Rails 3.1 already set up, including Ruby 1.9.2.

Refer to this article if you require assistance installing Ruby and Rails.

Create the application we’ll be working on, by running the following command in your Terminal:

rails new active_admin

Next, open your Gemfile and add the following lines:

gem 'activeadmin'
gem 'meta_search', '>= 1.1.0.pre'

The last gem is required for Active Admin to work with Rails 3.1, so don’t forget it. After that’s done, run the bundle install command to install the gems. Now, we need to finish installing Active Admin, by running the following command:

rails generate active_admin:install

This will generate all needed initializers and migrations for Active Admin to work. It will also create an AdminUser model for authentication, so run rake db:migrate to create all the needed database tables. Apart from that, you need to add one line to your config/environments/development.rb file, so sending emails works:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

Once that’s done, run rails server and point your browser to localhost:3000/admin. You’ll be greeted with a nice login form. Just type “admin@example.com” as the email and “password” as the password, and hit “Login”. You should now see a nice administration interface.


Step 2 – Configuring our User Model

As you can see from the webpage you just generated, there’s not much you can do, yet. We’re going to need a way to edit our users, and we can do that using Active Admin. The framework uses what it calls “Resources”. Resources map models to administration panels. You need to generate them using a command in your terminal, so Active Admin can know their existence, so go ahead and run:

rails generate active_admin:resource AdminUser

The syntax for that command is simple: just write the database model’s name at the end. This will generate a file inside the app/admin folder, called admin_users.rb. Now, if you refresh your browser you’ll see a new link at the top bar, called “Admin Users”. Clicking that will take you to the Admin User administration panel. Now, it’ll probably look a little too cluttered, since by default, Active Admin shows all of the model’s columns, and considering that the framework uses Devise for authentication, you’ll see a bunch of columns that are not really necessary. This takes us to the first part of our customization: the index page.

Admin User

Customizing Active Admin resources is fairly easy (and fun if you ask me). Open app/admin/admin_users.rb on your favorite text editor and make it look like this:

ActiveAdmin.register AdminUser do
  index do
    column :email
    column :current_sign_in_at
    column :last_sign_in_at
    column :sign_in_count
    default_actions
  end
end

Let’s review the code:

  • The first line is created by Active Admin, and, like it says, it registers a new resource. This created the menu link at the top bar and all of the default actions, like the table you just saw.
  • The index method allows us to customize the index view, which is the table that shows all rows.
  • Inside of the block you pass to the index method, you specify which columns you do want to appear on the table, ie. writing column :email will have Active Admin show that column on the view.
  • default_actions is a convenience method that creates one last column with links to the detail, edition and deletion of the row.

One final step for this view is to customize the form. If you click the “New Admin User” link on the top right, you’ll see that the form also contains all of the columns on the model, which is obviously not very useful. Since Active Admin uses Devise, we only need to enter an email address to create a user, and the rest should be taken care of by the authentication gem. To customize the forms that Active Admin displays, there’s a method, called (you guessed it) form:

ActiveAdmin.register AdminUser do
  index do
    # ...
  end

  form do |f|
    f.inputs "Admin Details" do
      f.input :email
    end
    f.buttons
  end
end

If the code looks familiar to you, you’ve probably used the Formtastic gem before. Let’s take a look at the code:

  • You specify the form’s view by calling the form method and passing it a block with an argument (f in this case).
  • f.inputs creates a fieldset. Word of advice: you have to add at least one fieldset. Fields outside of one will simply not appear on the view.
  • To create a field, you simply call f.input and pass a symbol with the name of the model’s column, in this case, “email”.
  • f.buttons creates the “Submit” and “Cancel” buttons.

You can further customize the forms using the DSL (Domain Specific Language) provided by Formtastic, so take a look at tutorials about this gem.

One last step for this form to work: since we’re not providing a password, Devise is not going to let us create the record, so we need to add some code to the AdminUser model:

after_create { |admin| admin.send_reset_password_instructions }

def password_required?
  new_record? ? false : super
end

The after_create callback makes sure Devise sends the user a link to create a new password, and the password_required? method will allow us to create a user without providing a password.

Go try it out. Create a user, and then check your email for a link, which should let you create a new password, and log you into the sytem.


Step 3 – Projects

We are going to create a simple Project Management system. Not anything too complicated though, just something that will let us manage projects and tasks for the project, and assign tasks to certain users. First thing, is to create a project model:

rails generate model Project title:string

Active Admin relies on Rails’ models for validation, and we don’t want projects with no title, so let’s add some validations to the generated model:

# rails
validates :title, :presence => true

Now, we need to generate an Active Admin resource, by running:

rails generate active_admin:resource Project

For now, that’s all we need for projects. After migrating your database, take a look at the interface that you just created. Creating a project with no title fails, which is what we expected. See how much you accomplished with just a few lines of code?


Step 4 – Tasks

Projects aren’t very useful without tasks right? Let’s add that:

rails generate model Task project_id:integer admin_user_id:integer title:string is_done:boolean due_date:date

This creates a task model that we can associate with projects and users. The idea is that a task is assigned to someone and belongs to a project. We need to set those relations and validations in the model:

class Task < ActiveRecord::Base
  belongs_to :project
  belongs_to :admin_user

  validates :title, :project_id, :admin_user_id, :presence => true
  validates :is_done, :inclusion => { :in => [true, false] }
end

Remember to add the relations to the Project and AdminUser models as well:

class AdminUser < ActiveRecord::Base
  has_many :tasks

  # ...
end
class Project < ActiveRecord::Base
  has_many :tasks

  # ...
end

Migrate the database, and register the task model with Active Admin:

rails generate active_admin:resource Task

Now go and take a look at the tasks panel in your browser. You just created a project management system! Good job.


Step 5 – Making It Even Better

The system we just created isn’t too sophisticated. Luckily, Active Admin is not just about creating a nice scaffolding system, it gives you far more power than that. Let’s start with the Projects section. We don’t really need the id, created and updated columns there, and we certainly don’t need to be able to search using those columns. Let’s make that happen:

index do
  column :title do |project|
    link_to project.title, admin_project_path(project)
  end

  default_actions
end

# Filter only by title
filter :title

A few notes here:

  • When you specify columns, you can customize what is printed on every row. Simply pass a block with an argument to it, and return whatever you want in there. In this case, we are printing a link to the project’s detail page, which is easier than clicking the “View” link on the right.
  • The filters on the right are also customizable. Just add a call to filter for every column you want to be able to filter with.

The project’s detail page is a little boring don’t you think? We don’t need the date columns and the id here, and we could show a list of the tasks more directly. Customizing the detail page is accomplished by using the show method in the app/admin/projects.rb file:

show :title => :title do
  panel "Tasks" do
    table_for project.tasks do |t|
      t.column("Status") { |task| status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
      t.column("Title") { |task| link_to task.title, admin_task_path(task) }
      t.column("Assigned To") { |task| task.admin_user.email }
      t.column("Due Date") { |task| task.due_date? ? l(task.due_date, :format => :long) : '-' }
    end
  end
end

Let’s walk through the code:

  • show :title => :title specifies the title the page will have. The second :title specifies the model’s column that will be used.
  • By calling panel "Tasks" we create a panel with the given title. Within it, we create a custom table for the project’s tasks, using table_for.
  • We then specify each column and the content’s it should have for each row.
    • The “Status” column will contain “Done” or “Pending” whether the task is done or not. status_tag is a method that renders the word passed with a very nice style, and you can define the color by passing a second argument with either : ok, :warning and :error for the colors green, orange and red respectively.
    • The “Title” column will contain a link to the task so we can edit it.
    • The “Assigned To” column just contains the email of the person responsible.
    • The “Due Date” will contain the date the task is due, or just a “-” if there’s no date set.

Step 6 – Some Tweaks for the Tasks

How about an easy way to filter tasks that are due this week? Or tasks that are late? That’s easy! Just use a scope. In the tasks.rb file, add this:

scope :all, :default => true
scope :due_this_week do |tasks|
  tasks.where('due_date > ? and due_date < ?', Time.now, 1.week.from_now)
end
scope :late do |tasks|
  tasks.where('due_date < ?', Time.now)
end
scope :mine do |tasks|
  tasks.where(:admin_user_id => current_admin_user.id)
end

Let’s review that code:

  • scope :all defines the default scope, showing all rows.
  • scope accepts a symbol for the name, and you can pass a block with an argument. Inside the block you can refine a search according to what you need. You can also define the scope inside the model and simply name it the same as in this file.
  • As you can see, you can access the current logged in user’s object using current_admin_user.
Tasks2

Check it out! Just above the table, you’ll see some links, which quickly show you how many tasks there are per scope, and lets you quickly filter the list. You should further customize the table and search filters, but I’ll leave that task to you.

We’re now going to tweak the task’s detail view a bit, since it looks rather cluttered:

show do
  panel "Task Details" do
    attributes_table_for task do
      row("Status") { status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
      row("Title") { task.title }
      row("Project") { link_to task.project.title, admin_project_path(task.project) }
      row("Assigned To") { link_to task.admin_user.email, admin_admin_user_path(task.admin_user) }
      row("Due Date") { task.due_date? ? l(task.due_date, :format => :long) : '-' } 
    end
  end

  active_admin_comments
end

This will show a table for the attributes of the model (hence the method’s name, attributes_table_for). You specify the model, in this case task, and in the block passed, you define the rows you want to show. It’s roughly the same we defined for the project’s detail page, only for the task. You may be asking yourself: What’s that “active_admin_comments” method call for? Well, Active Admin provides a simple commenting system for each model. I enabled it here because commenting on a task could be very useful to discuss functionality, or something similar. If you don’t call that method, comments will be hidden.

Tasks

There’s another thing I’d like to show when viewing a task’s detail, and that’s the rest of the assignee’s tasks for that project. That’s easily done using sidebars!

sidebar "Other Tasks For This User", :only => :show do
  table_for current_admin_user.tasks.where(:project_id => task.project) do |t|
    t.column("Status") { |task| status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
    t.column("Title") { |task| link_to task.title, admin_task_path(task) }
  end
end

This creates a sidebar panel, titled “Other Tasks For This User”, which is shown only on the “show” page. It will show a table for the currentadminuser, and all tasks where the project is the same as the project being shown (you see, task here will refer to the task being shown, since it’s a detail page for one task). The rest is more or less the same as before: some columns with task details.


Step 7 – The Dashboard

You may have noticed, when you first launched your browser and logged into your app, that there was a “Dashboard” section. This is a fully customizable page where you can show nearly anything: tables, statistics, whatever. We’re just going to add the user’s task list as an example. Open up the dashboards.rb file and revise it, like so:

ActiveAdmin::Dashboards.build do
  section "Your tasks for this week" do
    table_for current_admin_user.tasks.where('due_date > ? and due_date < ?', Time.now, 1.week.from_now) do |t|
      t.column("Status") { |task| status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
      t.column("Title") { |task| link_to task.title, admin_task_path(task) }
      t.column("Assigned To") { |task| task.admin_user.email }
      t.column("Due Date") { |task| task.due_date? ? l(task.due_date, :format => :long) : '-' }
    end
  end

  section "Tasks that are late" do
    table_for current_admin_user.tasks.where('due_date < ?', Time.now) do |t|
      t.column("Status") { |task| status_tag (task.is_done ? "Done" : "Pending"), (task.is_done ? :ok : :error) }
      t.column("Title") { |task| link_to task.title, admin_task_path(task) }
      t.column("Assigned To") { |task| task.admin_user.email }
      t.column("Due Date") { |task| task.due_date? ? l(task.due_date, :format => :long) : '-' }
    end
  end
end

The code should be fairly familiar to you. It essentially creates two sections (using the section method and a title), with one table each, which displays current and late tasks, respectively.

Dashboard

Conclusion

We’ve created an extensive application in very few steps. You may be surprised to know that there are plenty more features that Active Admin has to offer, but it’s not possible to cover them all in just one tutorial, certainly. If you’re interested in learning more about this gem, visit activeadmin.info.

You also might like to check out my project, called active_invoices on GitHub, which is a complete invoicing application made entirely with Active Admin. If you have any questions, feel free to ask them in the comments, or send me a tweet.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.colourgraphicdesign.com rey

    Do they have something like this also for php?

  • http://chrismorgan.info Chris Morgan

    A smiley filter is making a mess of this with things like :only – it’s turning it into (surprised smiley)nly.

    sidebar “Other Tasks For This User”, nly => :show do

    • http://twitter.com/Synt4x Ian Murray
      Author

      I noticed, I will notify the editor ;)

  • Craig

    My supervisor has asked me to look into this, bookmarked your article for later use.

    One thing they need to fix though is their website, it doesn’t work well in 1024×768. I know it’s small, but little things like that put me off…

  • w1sh

    The Django-killer arrives.

    • wip

      right.. I can see it now.. seas of python enthusiastic switching to ruby lol

  • http://www.ssiddharth.com Siddharth

    This looks excellent! I’m gonna experiment with this a bit today.

  • http://www.zerply.com/profile/markprovan Mark Provan

    This is awesome! Going to implement this into my current Rails project tonight. Thanks for an in-depth tutorial :)

  • http://kylemorin.tumblr.com Kyle Morin

    If you are having some troubles installing active_admin because of missing js runtime:
    Add this to your gemfile and re-run bundle install.

    gem ‘execjs’
    gem ‘therubyracer’

    Should work after that.

  • Carlos Saavedra

    This application is great, saves a lot of time and is reliable

  • http://blogs.desales.edu/deit Steve

    I am having some trouble installing this on my Ubuntu VM. I am getting an “undefined method ‘to_sym’” error on the rails generate active_admin:install part. I am using RVM (Ruby 1.9.2 and Rails 3.1.0) and have just updated my system gems.

    Thanks!

    • http://twitter.com/Synt4x Ian Murray
      Author

      That’s weird. I didn’t have any problems using the same development env, although I’m on a mac. Are you sure you included the meta_search gem? If you’re still having trouble I recommend you open a ticket on Active Admin’s GitHub repo.

      • http://blogs.desales.edu/deit Steve

        Yup. I’ll search around forums and see if I can find a solution… if not, to the repo it is!

    • http://limetree.org Jamie

      I’m also getting this error.

    • Aleksei

      I have the same error too !

    • http://www.wikijob.co.uk Chris Muktar

      Me too!

  • Alexander Tipugin

    This is awesome, never heard about this gem before. Great stuff!

  • jv

    running into problems below, any thoughts?

    jmbp17:active_admin j2$ rails generate active_admin:install
    /Users/j2/active_admin/config/application.rb:13:in `’: superclass mismatch for class Application (TypeError)
    from /Users/j2/active_admin/config/application.rb:12:in `’
    from /Users/j2/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:21:in `require’
    from /Users/j2/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:21:in `’
    from script/rails:6:in `require’
    from script/rails:6:in `’
    jmbp17:active_admin j2$

    • http://twitter.com/Synt4x Ian Murray
      Author

      I suppose you’re using the latest gem versions. Did you include the meta_search gem? I created everything from scratch for this tutorial, so you shouldn’t have any trouble if you’re using the same dev env. Could you elaborate on the issue? Platform, versions, etc.?

      • jv

        Yep, platform is OSX 10.6.8, ruby version is 1.9.2p290…. but no joy

      • http://twitter.com/Synt4x Ian Murray
        Author

        I’m using ruby-1.9.2-p180 on the same platform. But I don’t think that’s the problem.

    • http://blogs.desales.edu/deit Steve

      @jv

      I ran into the same problem. Make sure your system gems are up to date (gem update –system). Also, where I ran into trouble was generating a new application with the name of active_admin. Try generating a rails app with a different name (rails new MyProject – for example). I think if you create the app with the name active_admin, it is creating a duplicate class somewhere, hence the class mismatch error.

      I am also using the mysql gem, not sqlite. I had to make sure my database.yml file was updated and databases were created prior to running the active_admin install.

      Hope this helps!

      • http://twitter.com/Synt4x Ian Murray
        Author

        That is probably the error. Sorry about that! For the people that are having problems please try a different project name! :)

    • alsenda

      For anyone still having this issue:

      Via: http://stackoverflow.com/questions/10087737/activeadmin-error-no-superclass-method-buttons

      seems like formtastic 2.2.0 (released today) breaks active_admin and since active_admin requires formtastic >= 2.0.0… put in your Gemfile this

      gem “formtastic”, “~> 2.1.1″
      gem “activeadmin”, “~> 0.4.3″

      then run

      bundle update formtastic

      then restart your server (if you have it running).

      and should work ok…

    • http://mehmetbolak.com Mehmet Bolak

      I’m having the exact same problem! Dev env Ruby 1.9.3 p-125. If there is anyway I can get some help I would greatly appreciate it.

  • http://jaimievansanten.nl Jaimie van Santen

    Login credentials provided don’t work with the demo files…

    • http://twitter.com/Synt4x Ian Murray
      Author

      Sorry about that. That’s because the demo files don’t come with a database. To fix that you can always enter the rails console and create a user by hand, you just need to provide an email address, Devise should send an email upon creation with a link to reset the password.

  • Nelson

    Hi, I’m having trouble getting this to work, when I try run the “rails generate active_admin:install” command it gives me an error like ‘: superclass mismatch for class Application (TypeError).

  • jv

    Tried it on Lion (completely clean install) as well, same problem.
    Something is not right.
    /Users/j2/active_admin/config/application.rb:13:in `’: superclass mismatch for class Application (TypeError)
    from /Users/j2/active_admin/config/application.rb:12:in `’
    from /Users/j2/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:21:in `require’
    from /Users/j2/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:21:in `’
    from script/rails:6:in `require’
    from script/rails:6:in `’

    • http://twitter.com/Synt4x Ian Murray
      Author

      Try what matll mentioned, and create the project with a different name, by running rails generate active_admin_tutorial or something like that ;)

  • mattl

    For those having problems with the ‘superclass mismatch’ error. The problem seems to be that the name of the new Application we create in step 1 shouldn’t be active_admin as it conflicts with the name of the gem ‘active_admin’.

    So to fix start from scratch and name your initial application something unique to you e.g.

    rails new myunique_active_admin_test

    Hope that helps someone.

  • http://www.notes.kloop.kg Said

    Yeahh ))) this is Ruby! I do remember I used such a gem year ago in one project )))

  • http://evansofts.com Evan-XG

    Please , is there any alternative to just have the raw html for other platform integration.
    I am still sticking with php (zend & CI ) and I think using this nice framework is not a good reason for me to get into ruby .
    I could do some hack but the licence is not clear for me . (commercial product )

  • http://www.jeffadams.co.uk Jeff Adams

    I don’t know any RUby at all but as an Admin Template author over at Themeforest I’d actively encourage any developers to try and use this as ultimately it just makes the backends look much prettier.

    Backends should never be forgotten about, they need to be user friendly too :-)

  • Tony Christie

    Great tutorial, I’ve just worked through it and have a few “tweaks” which might catch out RubyNoobs like myself:

    1. Need to “rake db:migrate” at the end of section 3 and 4
    2. The smiley filter is at work in the code sections in 5,6, and 7 – the image tag should just be colon ok – took me a while to figure that one out ;)

    Neat framework and nice tutorial, thanks again.

    • http://www.jeffrey-way.com Jeffrey Way

      Those smileys are so irritating. Not sure why they’re registering in the code as well.

      Anyhow, I just went ahead and disabled smileys on the site. All fixed now. Sorry about that!

  • jv

    Sorry, I don’t want to appear ungrateful (I’m not)… but is it possible to fix this tutorial so that it works and doesn’t fail? It’s tough to read a tutorial on a new subject, then read the comment threads and put it all together into something that works…. I’m just asking….

    • Sam

      No more gotchas except:

      1) As mentioned above don’t name the project like the gem active_admin.

      2) When lazily copy and pasting code it pays to capture all :)

      3) The “Devise Confirmation Email” will only be visible is in the server log!

      Great Tutorial !!!

  • Phil Cairns

    I worked my way through the tutorial, and was very happy once all the little bits and pieces were resolved. I like the menus, the forms, the lot. However, as I want to base a complete application on ActiveAdmin, is it possible to make it run without the “/admin” prefix in the URL?

    • http://activeadmin.info Matt Vague

      @phil It’s totally possible to do what you’re talking about, simple too.

      After installing ActiveAdmin, go to config/initializers/active_admin.rb and change:

      config.default_namespace = :admin

      to

      config.default_namespace = false

      You will then be able to navigate to “/” to access ActiveAdmin.

      • Phil Cairns

        Thanks, Matt. Worked like a charm, as soon as I’d deleted public/index.html :-)

  • Luan Nguyen

    Does anyone use Devise confirmation email with Active Admin? I tried the Devise confirmation option but it didn’t work.

  • Alexander Tipugin

    After a little bit of testing all that i can say is this is very promising plugin, but too buggy at the moment

  • Eric

    In the task form, the admin dropdown doesn’t display admin emails but some kind of admin addresses in memory, is there a way to change that ?

    ANd thank you very much for this tutorial.

    • http://twitter.com/Synt4x Ian Murray
      Author

      The easiest way is to add a “name” attribute to the AdminUser model (by creating a migration). Another way is to customize the form, but that’s more work. ;)

      • Eric

        Thank you ! The migration and some little adjustments in the model and controller and it works nicely !

      • Noel H

        I am having the same issue, where the dropdown displays “#<AdminUser:0×000…" I am still very new to Rails and do not quite understand how to solve it, even with your reply. By adding a “name” attribute to the AdminUser model through migration, do you mean just adding a "name" column to the Admin User table through migration? Does that mean that, by default, the form is expecting a "name" field and when it does not find one Rails generates that string instead?

        Thanks for the great tutorial. It's easy to follow and you've done a great job of explaining what the code means.

      • Vezu

        I have the same problem as Noel H, I followed the tutorial to the dot. Any ideas how i solve “I am having the same issue, where the dropdown displays “#<AdminUser:0×000…" I am still very new to Rails and do not quite understand how to solve it, even with your reply. By adding a “name” attribute to the AdminUser model through migration, do you mean just adding a "name" column to the Admin User table through migration? Does that mean that, by default, the form is expecting a "name" field and when it does not find one Rails generates that string instead?"

      • http://www.sigididesign.com Vezu

        I answer myself. Needs a name. So i created a migration as per advise, Thanks. I love this.

      • Noel H

        I guess it really was that simple. Thanks, Ian and Vezu.

  • Alex

    Hi,
    Congratulation for the post!, it’s clear and simple.

    After downloading I have typed: bundle install to update all my gems and after that I have launched the server, but I get this following error:

    /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load’: /Users/alex/Desktop/ianmurrays/config/initializers/session_store.rb:3: syntax error, unexpected ‘:’, expecting $end (SyntaxError)
    …sion_store :cookie_store, key: ‘_active_projects_session’

    Any suggestion is appreciated.

    Thank

    • http://twitter.com/Synt4x Ian Murray
      Author

      Are you sure you’re running Ruby 1.9.2? If you are, try reinstalling all gems and downloading the source code again. It looks like a very strange error.

  • kuldeep

    good tutorials………………..keep it up….

    thanks u a lot..:P

  • http://www.7lifedesign.com Yordan

    I will try this Admin panel. Thank you for sharing this.

  • mike

    How would you get info from the join table in a has many :through relationship when creating a panel in the show view?

  • http://www.21waves.com Nelson

    In an ideal app, you will have an admin backend and a user accounts. In Magento you have customer accounts where they manage their purchases and details. Therefore URLs like:-

    http://example.com/admin and http://example.com/user_account

    How can you achieve the same using Active Admin. Its not clear to me although I have understood the admin side. The client side is pretty important for my app.

    Regards

  • Hassan

    Hello guys I want to know how to :

    -change the active admin navigation bar color(which is grey) to another color(orange for example)
    -use my own icons on the navigation bar links

    Thanks for helping !!!!!

    • http://www.activeadmin.info Matt

      Hassan, what you’re talking about is quite simple.

      After installing ActiveAdmin simply open up the generated active_admin.css.scss file (should be in either app/assets/ or public/stylesheets) and make it look something like this:

      // Active Admin CSS Styles
      @import “active_admin/mixins”;

      $primary-color: #f49212;
      // Other custom colours here

      @import “active_admin/base”;

      // To customize the Active Admin interfaces, add your
      // styles here:

      To see a list of colours and things that can be changed, check this out:

      https://github.com/gregbell/active_admin/blob/master/app/assets/stylesheets/active_admin/mixins/_variables.css.scss

  • Erwan Ripoll

    Great tut!
    Thanks a bunch for that.

    One question though. I’m a ROR newbie and I’m planning on using this for a Portfolio system for Artists.
    Let’s say I have a Article model linked to my Admin User model (User has_many articles).
    I want my admin user to only be able to create article for himself.
    How can I make it so that admin_user_id of newly created articles is always the one of the logged in user?
    Thanx a million in advance.

  • http://ygamretuta.me Ygam Retuta

    for anyone wishing to deploy Active Admin on Heroku with Rails 3.1 and a good handling of the assets pipeline, check out my tutorial:

    http://ygamretuta.me/2011/10/02/setting-up-active-admin-on-heroku-with-rails-3-1-and-cedar/

  • Frank

    Hi, I checked all the things its worked fine with sqlite3 but it gives me syntax error on mysql2. So please guide me on that…The error is given below. thanks

    SyntaxError in ActiveAdmin::Devise::SessionsController#new

    C:/railstack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:91: syntax error, unexpected keyword_end
    C:/railstack/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:93: syntax error, unexpected $end, expecting keyword_end

  • http://www.bizmo.co.uk Robbie Done

    Is there a way to integrate creditor or tinymce?

  • rem

    When i try to create a new user i get the following error message.

    Could not find a valid mapping for #

    parameters:
    {“utf8″=>”✓”,
    “authenticity_token”=>”OSkMJMZ8KzWJpxG6i8/buKdlD8Jn5XZgsi52hlUqulI=”,
    “admin_user”=>{“email”=>”tes6@example.com”},
    “commit”=>”Create Admin user”}

    session trace:
    app/models/admin_user.rb:10:in `block in ‘

  • rem

    sorry left out the mapping error message in last comment.
    Could not find a valid mapping for ‘#’<AdminUser id: 7, email: "tes6@example.com", encrypted_password: "", reset_password_token:….

  • http://ivanoats.com Ivan Storck

    I’m also getting the same valid mapping error, and so is a coworker. Any tips?

    • Steve

      Hey Ivan,

      Did you ever figure this out?

      Regards,
      Steve

      • Jose

        I have the same problem, can anyone tell me how to fix it?

        Thanks!

  • Ankit Varshney

    Migration fails if you have configured the table prefix in application.rb. But I fixed it by adding the prefix in migration.

    May be this can be because of rails rename_table method issue. As it do not check the prefix/suffix and directly executes the query.

    But finally I like this gem.
    Great work Buddy :).

    • Ankit Varshney

      I am using prefix in my tables so there should be some way that active_admin should detect itself and use it. It fails for db.active_admin_comments as table name is xyz_active_admin_comments.

      So please suggest.

  • Jason

    I too get this error Could not find a valid mapping for #<AdminUser id: 4, email:

    has anyone figured out a solution?

    • Steve Sheldon

      Hey Guys,

      if you are getting this problem, I have somewhat of a solution, not perfect but if you set:

      config.cache_classes = false

      in config/environments.development.rb

      After doing this every time you edit you will have to restart the web server so I would just switch it on to test that part and switch it off when you don ‘t need it.

      My environment is rails 3.1

      Hope this helps somebody.

    • http://www.acid.cl Gonzalo

      add a column name. works like a charm

      • Gonzalo

        i found this in application.rb

        setting :display_name_methods, [ :display_name, :full_name, :name, :username, :login, :title, :email, :to_s ]

  • Jo Santana

    I’m trying setup the AdminUser with a nested Profile model, but I can’t make it work properly.

    The Profiles fields are there, but when I hit the save button, only the AdminUser data is saved/updated; Profile data is ignored. But when I enter Profile data from its page, it shows up on AdminUser edit form. But again, I just can’t update Profile data from there.

    Can anybody help me with that? I just don’t know what to do anymore.

    FILE >> app/models/admin_user.rb

    has_one :profile, :dependent => :destroy
    accepts_nested_attributes_for :profile, :allow_destroy => true

    FILE >> app/models/profile.rb

    belongs_to :admin_user

    FILE >> app/admin/admin_users.rb

    form :partial => ‘form’

    FILE >> app/views/admin/admin_users/_form.html.erb

  • pvvsmk

    hi, i am new to Ruby On Rails… i am creating a new project by using active admin tool.. will u please help me how to add a controller (with index action only) to dash board.

  • Anon

    Your invoicing app is not working. Had to delete gemfile.lock but after I got the server started, I get:

    Syntax error: File to import or load not found or unreadable: bourbon

  • Thomas

    I am having a issue with tweeking my project when I paste in
    show :title => :title do
    panel “Tasks” do
    table_for project.tasks do |t|
    t.column(“Status”) { |task| status_tag (task.is_done ? “Done” : “Pending”), (task.is_done ? :ok : :error) }
    t.column(“Title”) { |task| link_to task.title, admin_task_path(task) }
    t.column(“Assigned To”) { |task| task.admin_user.email }
    t.column(“Due Date”) { |task| task.due_date? ? l(task.due_date, :format => :long) : ‘-’ }
    end
    end
    end
    I get an error saying “is_done” is undefined. I’m very new to this I mean NEW like yesterday was my first day hearing about ruby EVER. Everything else worked until I got to “Make it Even Better” part. I get a ton of undefined methods “task.where” and “task.is_done” don’t work. Please help

    • alsenda

      I’m guessing, but maybe you pasted the code in the /app/model/’s files instead of the ones in /app/admin/. That would explain why the method can’t be found.
      Hope this helps.

      Good coding!

  • marco

    ODBC::Error: 23000 (2601) [unixODBC][FreeTDS][SQL Server]Cannot insert duplicate key row in object ‘dbo.admin_users’ with unique index ‘index_admin_users_on_reset_password_token’.: EXEC sp_executesql N’INSERT INTO [admin_users] ([created_at], [current_sign_in_at], [current_sign_in_ip], [email], [encrypted_password], [last_sign_in_at], [last_sign_in_ip], [remember_created_at], [reset_password_sent_at], [reset_password_token], [sign_in_count], [updated_at]) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident’, N’@0 datetime, @1 datetime, @2 nvarchar(255), @3 nvarchar(255), @4 nvarchar(255), @5 datetime, @6 nvarchar(255), @7 datetime, @8 datetime, @9 nvarchar(255), @10 int, @11 datetime’, @0 = ’2012-05-28T13:54:08.827′, @1 = NULL, @2 = NULL, @3 = N’adsd@efer.com’, @4 = N”, @5 = NULL, @6 = NULL, @7 = NULL, @8 = NULL, @9 = NULL, @10 = 0, @11 = ’2012-05-28T13:54:08.827′

    error create new user

  • http://tonytonyjan.github.com tonytonyjan

    active_admin is still too buggy.

  • Dakota Lightning

    Im getting an

    rake aborted!
    uninitialized constant Project

    everytime I do a rake db:migrate after step 3.

    Rails => 3.2.6
    OS X 10.7.4

  • Sebastian

    Hi, i’m trying to install this on my custom name application (admintest) and i get this error:

    Could not find generator admintest:install.

    Do you know how should i resolve this?
    My env: Ubuntu – Rails ’3.2.6′ – Ruby 1.9.2

  • king

    Exits tutorial step to step translate activeadmin?

  • John

    Hi,

    I am kind of new to rails but still was able to understand your tutorial. I was trying to modify your tutorial to create task based on the projects_id. So the route would be something like

    http://localhost:3000/admin/projects/1/task/new

    I’ve tried creating an action item with member actions but it doesn’t seem to work:

    # Create Task from Project
    action_item :only => :show do
    link_to “Create Task”, task_new_admin_project_path(resource)
    end

    member_action :task_new do
    @project = Project.find(params[:id])
    redirect_to new_admin_task_path(@projects)
    end

    I keep getting redirected to the /admin/task/new route. And the project_id of the new task is not set by default to the current project_id. Is it possible to do this with active_admin? And How do I accomplish this?

    Btw, active_admin is just awesome.

    Thanks.
    John

  • Andreas Schneider

    I have completed this great tutorial. Nice work.
    I have just one question.
    When I want to create a new task, the Admin user dropdown displays # .
    Is there a way to change this into displaying the registered e-mail instead?