Created
November 21, 2012 09:15
-
-
Save mildfuzz/4123935 to your computer and use it in GitHub Desktop.
User Admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActiveAdmin.register User do | |
| filter :first_name | |
| filter :last_name | |
| filter :company_name | |
| filter :email | |
| form do |f| | |
| f.inputs "Contact" do | |
| f.input :first_name | |
| f.input :last_name | |
| f.input :company_name | |
| f.input :email | |
| f.input :contact_number | |
| end | |
| f.buttons | |
| end | |
| index do | |
| column :id | |
| column :full_name | |
| column :company_name | |
| column :email, :sortable => false | |
| column :contact_number, :sortable => false | |
| column "Total Spend", :sortable => :total_spend do |u| | |
| money_format(u.total_spend) | |
| end | |
| column "Orders" do |u| | |
| u.orders.count | |
| end | |
| default_actions | |
| end | |
| show do |u| | |
| attributes_table do | |
| row :full_name unless user.full_name.blank? | |
| row :company_name unless user.company_name.blank? | |
| row :id | |
| row "Total Spend" do |u| | |
| money_format(u.total_spend) | |
| end | |
| row "Order Count" do |u| | |
| u.orders.length | |
| end | |
| row :email | |
| row :contact_number | |
| end | |
| panel "Order History" do | |
| # end | |
| table_for(user.orders) do | |
| column :created_at | |
| column :id | |
| column "Spend" do |o| | |
| money_format(o.order_cost) | |
| end | |
| column "Status" do |o| | |
| o.fulfillment_status | |
| end | |
| column "Financial Status" do |o| | |
| o.financial_status | |
| end | |
| column "Actions" do |o| | |
| link_to("View", admin_order_path(o.id))+"/"+link_to("Edit", edit_admin_order_path(o.id)) | |
| end | |
| end | |
| end | |
| end | |
| controller do | |
| def scoped_collection | |
| User.joins(:orders).select("users.*, MAX(orders.order_cost) AS total_spend") | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| has_many :orders | |
| # Include default devise modules. Others available are: | |
| # :token_authenticatable, :confirmable, | |
| # :lockable, :timeoutable and :omniauthable | |
| devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable | |
| # Setup accessible (or protected) attributes for your model | |
| attr_accessible :email, :password, :password_confirmation, :remember_me, :contact_number, :first_name, :last_name, :company_name | |
| # attr_accessible :title, :body | |
| def total_spend | |
| self.orders.sum(&:order_cost).to_f | |
| end | |
| def full_name | |
| first = self.first_name||"" | |
| last = self.last_name||"" | |
| first + last == "" ? "" : first+" "+last | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment