Showing posts with label active admin. Show all posts
Showing posts with label active admin. Show all posts

Sunday, 26 August 2012

Active admin relationships between models

I have used active admin for my rails application admin section.

I have 2 tables products and category.

Product class

belongs_to :category


Category class

has_many :products



I have created two resources for the above two models in admin folder. Every thing went well and for both the resources its displaying the list view perfectly.

When I try to create the product from product new screen its displaying the categories options as list of all categories objects and not the categories records.

I have made some goggling and came to find solution that we need add the below method in my category class to display the category names in the drop down to choose while creating the product.


In my category class

  def to_s
    category_name
  end


Thank You,
Uma Mahesh.

generating active admin controller

Hi,

Active admin provides a good admin interface. Inorder to generate a controller in active admin you need to run the below command

> rails g active_admin:resource User

The actual notation that should be used for active for a model is 'resource'. By running the above command you will create a resource for user class.

We need to refer the active admin classes as resource for model class.

Thank You,
Uma Mahesh.

Wednesday, 22 August 2012

Custamize active admin find_by request instead of ID

Hi,

I have a requirement, where I need to find the record with find_by_name in active admin. But by default active admin finds the records with id. After googling I came to see this can be done by using before_filter as below

ActiveAdmin.register Product do
    before_filter :only => [:show, :edit, :update, :destroy] do
        @product = Product.find_by_name(params[:id])
      end
end

Thank You,
Uma Mahesh.

Sunday, 3 June 2012

active admin show page customisation

Hi,

You can customise show method in active admin for your desired output. I have customise show page to have different panels of user show page.


  show :title => "User details" do | user |
    panel "Profile Info" do
    attributes_table_for user do
      row("Name") {|user| user.p.f_name}
      row :email
      row("Company") {|user| user.p.company}
     end
    end

    panel "Email Notifications"  do
      attributes_table_for user do
        row("News Letter") { |user| user.p.notification_setting.news) }
        row("New Events") { |user| user.p.notification_setting.events) }
      end
    end
  end

Here is the link to have clear view about customisation of show page:
https://gist.github.com/986730



Thank You,
Uma Mahesh

Monday, 7 May 2012

How to hide filters in the active admin view

Hi,

I am working with active admin customisation for one of my project. In that I need to hide the filters in the list views.

This can be done with simple configuration as shown below

ActiveAdmin.register Product do

config.clear_sidebar_sections!

end

The above configuration will make filters not to display in the list view.

Thank You,
Uma Mahesh

How to hide API & Downloads links in the active admin

Hi,

I am working with active admin customisation for one of my project. In that I need to hide the API & Downloads links in the list views.

I have searched for it making it configurable at controller level. But I came to see there is no such provision.

By goggling I found solution as this can done through css path. I.e making the css class for that text to be hide.

Here is the style that need to be added in the active admin css style sheet.

In app/assets/stylesheets/active_admin.css.scss

.index #active_admin_content #index_footer {
  color: white;
  a {
    display: none;
  }
}

This will make the download links hide in the view.

Thank You,
Uma Mahesh.