Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#104] Add ransack gem #110

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -362,6 +369,7 @@ DEPENDENCIES
pundit
rails (~> 6.0.2)
rails-controller-testing
ransack
redcarpet
rspec
rspec-rails
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/yarn_database_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions app/presenters/yarn_database_presenter.rb
Original file line number Diff line number Diff line change
@@ -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