Rails : Customize Rails Admin engine

I wondered what these terms like collection and member mean.

member :activate do
  only ['Contractor']
  i18n_key :activate
end

collection :painter_photos do
  i18n_key :painter_photos
end

member: These are actions applicable to individual records in the model. This will show up in every row like.

collection: applicable to the model as a whole

How to add custom action in particular row?

member :activate do
  only ['Contractor']
  i18n_key :activate
end

for this you would need to put

# in views/rails_admin/main/activate.haml
- if @object.is_a?(Contractor)
  - if @object.active?
    %p Already Activated
  - else
    %p You are about to activate a contractor.
    %p
      Name:
      %b
        = @object.full_name
    = link_to "Activate Contractor", main_app.admin_activate_contractor_path(@object), confirm: "Are you sure?", class: "btn"
- else
  %p Sorry, only contractors can be activated.

and

# in rails_admin.en.yml
activate:
  title: "Activate"
  menu: "Activate"
  breadcrumb: "Activate"

 

Custom Label

field :painters, :boolean do
  label do
    "Send to all contractors"
  end

  render do
    content =  bindings[:form].check_box :painters
    bindings[:view].render inline: content
  end
end

Customize the Edit / New Form

You can customize the button names in the form but in a tricky way. For example lets try to change the button names like Save to Send and so.

copy the file

https://github.com/sferik/…/_submit_buttons.html.haml this page in your repo at “views/rails_admin/main/_submit_button.html.haml”

and put conditional like

- if params['model_name']  == 'broadcast' && params['action'] == 'new'
  %button.btn.btn-primary{type: "submit", name: "_save", :'data-disable-with' => t("admin.models.broadcast.save")}
    %i.icon-white.icon-email
    = t('admin.models.broadcast.save')
- else
  %button.btn.btn-primary{type: "submit", name: "_save", :'data-disable-with' => t("admin.form.save")}
    %i.icon-white.icon-ok
    = t("admin.form.save")

and add some i18n keys in rails_admin.en.yml like

en:
  admin:
    loading: "Loading..."
    home:
      name: "Home"
    pagination:
      previous: "« Prev"
      next: "Next »"
      truncate: "…"
    models:
      broadcast:
        save: 'Send Message'
        save_and_add_another: 'Send and prepare for next'
        save_and_edit: 'Send and Edit'
Advertisements

Pie Charts in Rails Admin

 With Rails Admin

If you are using RailsAdmin for managing you web-application from backend, you get reports for your data out of the box. In addition you can edit/update in no time with ease. You will not have charts and graph at that instant though.

How can I get Charts?

Continue reading

Reporting in Rails : Report generation : Downloadable in any Format | PDF | CSV | XLS

Working on report generation is a time consuming task yet very necessary for any software projects. End of the day every business owner needs to see where their business stands or see ongoing activity in the system. Reports need list of records and Graphs/Charts to show the big-picture at a glance.

 With Rails Admin

If you are using RailsAdmin for managing you web-application from backend, you get reports for your data out of the box. In addition you can edit/update in no time with ease. You will not have charts and graph at that instant though.

How can I get Charts?

Continue reading