ruby on rails - How should i show monthly generated tickets through chartkick -
i using rails 4, , want show monthly ticket generated through pie charts. can help?
schema:
create_table "tickets", force: :cascade |t| t.integer "store_id" t.integer "vendor_id" t.datetime "ticket_date" t.datetime "deadline" t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "ticket_no" t.string "vendor_name" t.string "user_id" t.integer "issue_id" t.integer "category_id" t.boolean "completed", default: false
end
my ticket.rb
contains:
def self.category_count(user,category) if user.vendor.nil? category.tickets.where('store_id = ?', user.store.id) else category.tickets.where('vendor_id = ?', user.vendor.id) end end def self.ticket_count(user,ticket) if user.vendor.nil? ticket.tickets.where('store_id = ?', user.store.id) else ticket.tickets.where('vendor_id = ?', user.vendor.id) end end
view: tickets:
index.html.erb file is:
<% data = {} %> <% category in category.all %> <% data[:"#{category.name}"] = ticket.category_count(current_user,category).count %> <% end %> <%= pie_chart(data) %>
i start moving view helper method such as:
def pie_chart_data(user) hash[*category.all.map { |c| [c.name, ticket.category_count(user, c).count] }] end
you call in view
<%= pie_chart(pie_chart_data(current_user)) %>
Comments
Post a Comment