diff --git a/Gemfile b/Gemfile index 97300f6..d78df14 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,7 @@ gem 'font-awesome-sass' gem 'kaminari' gem 'mini_racer' gem 'pundit' +gem 'ransack' gem 'redcarpet' gem 'sprockets' gem 'sprockets-rails', require: 'sprockets/railtie' diff --git a/Gemfile.lock b/Gemfile.lock index c5d1b0b..c80879c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -197,6 +197,8 @@ GEM nokogiri (1.10.9) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) + polyamorous (2.3.2) + activerecord (>= 5.2.1) popper_js (1.16.0) pry (0.13.1) coderay (~> 1.1) @@ -243,6 +245,11 @@ GEM rake (>= 0.8.7) thor (>= 0.20.3, < 2.0) rake (13.0.1) + ransack (2.3.2) + activerecord (>= 5.2.1) + activesupport (>= 5.2.1) + i18n + polyamorous (= 2.3.2) rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) @@ -362,6 +369,7 @@ DEPENDENCIES pundit rails (~> 6.0.2) rails-controller-testing + ransack redcarpet rspec rspec-rails diff --git a/app/controllers/yarn_database_controller.rb b/app/controllers/yarn_database_controller.rb index 9e12253..57c36b0 100644 --- a/app/controllers/yarn_database_controller.rb +++ b/app/controllers/yarn_database_controller.rb @@ -3,12 +3,13 @@ class YarnDatabaseController < ApplicationController before_action :set_yarn_product, only: [:show, :edit, :update, :update_attribution] + # before you switch this to the cards layout. remember you've got a json view too def index @yarn_products = YarnProduct.all - .public_send(sort_order_scope) - .includes(:yarn_company) - .with_attached_image - .page(params[:page]) + .public_send(sort_order_scope) + .includes(:yarn_company) + .with_attached_image + .page(params[:page]) end def show diff --git a/app/presenters/yarn_database_presenter.rb b/app/presenters/yarn_database_presenter.rb new file mode 100644 index 0000000..2852f3d --- /dev/null +++ b/app/presenters/yarn_database_presenter.rb @@ -0,0 +1,32 @@ +class YarnDatabasePresenter + include ActionView::Helpers + include Rails.application.routes.url_helpers + + def self.page_title + 'Yarn Database' + end + + def self.sidebar + new.sidebar + end + + def self.card_title(yarn_product) + new.card_title(yarn_product) + end + + def self.card_description(_) + nil + end + + def self.sorting_options_partial + 'yarn_database/sorting_options' + end + + def sidebar + link_to 'Add Yarn to Database', new_yarn_product_path, class: 'list-group-item' + end + + def card_title(yarn_product) + link_to yarn_product.name, yarn_product, class: 'stretched-link' + end +end