-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add species url param * remove species select from index * update select for breed * add species param to breed select * add pet species button's to nav * add species link to home page for logged in user * adjust font size * change dropdown to individual buttons * change external form page to use individual buttons * remove unused page * use module * change logout path * i18n * more i18n * add species to header * change link helper * update tests for species specific / remove brital tests * change test to use module * add set_species and move breeds method to Pet model * remove useless conditional * update test * comments
- Loading branch information
Showing
11 changed files
with
158 additions
and
246 deletions.
There are no files selected for viewing
This file contains 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
92 changes: 52 additions & 40 deletions
92
app/controllers/organizations/adoptable_pets_controller.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,60 @@ | ||
class Organizations::AdoptablePetsController < Organizations::BaseController | ||
include ::Pagy::Backend | ||
|
||
skip_before_action :authenticate_user! | ||
skip_verify_authorized only: %i[index] | ||
before_action :set_likes, only: %i[index show], | ||
if: -> { allowed_to?(:index?, Like) } | ||
helper_method :get_animals | ||
|
||
def index | ||
@q = authorized_scope(Pet.unadopted, with: Organizations::AdoptablePetPolicy).ransack(params[:q]) | ||
@pagy, paginated_adoptable_pets = pagy( | ||
@q.result.includes(:adopter_applications, :matches, images_attachments: :blob), | ||
limit: 9 | ||
) | ||
@pets = paginated_adoptable_pets | ||
end | ||
module Organizations | ||
class AdoptablePetsController < Organizations::BaseController | ||
include ::Pagy::Backend | ||
|
||
skip_before_action :authenticate_user! | ||
skip_verify_authorized only: %i[index] | ||
before_action :set_likes, only: %i[index show], | ||
if: -> { allowed_to?(:index?, Like) } | ||
before_action :set_species, only: %i[index] | ||
|
||
def index | ||
@q = authorized_scope( | ||
case @species | ||
when "dog" | ||
Pet.Dog.unadopted | ||
when "cat" | ||
Pet.Cat.unadopted | ||
else | ||
redirect_back_or_to root_path and return | ||
end, | ||
with: Organizations::AdoptablePetPolicy | ||
).ransack(params[:q]) | ||
|
||
def show | ||
@adoptable_pet_info = CustomPage.first&.adoptable_pet_info | ||
@pet = Pet.find(params[:id]) | ||
authorize! @pet, with: Organizations::AdoptablePetPolicy | ||
|
||
if current_user&.latest_form_submission | ||
@adoption_application = | ||
AdopterApplication.find_by( | ||
pet_id: @pet.id, | ||
form_submission_id: current_user.latest_form_submission.id | ||
) || | ||
@pet.adopter_applications.build( | ||
form_submission: current_user.latest_form_submission | ||
) | ||
@pagy, paginated_adoptable_pets = pagy( | ||
@q.result.includes(:adopter_applications, :matches, images_attachments: :blob), | ||
limit: 9 | ||
) | ||
|
||
@pets = paginated_adoptable_pets | ||
end | ||
end | ||
|
||
private | ||
def show | ||
@adoptable_pet_info = CustomPage.first&.adoptable_pet_info | ||
@pet = Pet.find(params[:id]) | ||
authorize! @pet, with: Organizations::AdoptablePetPolicy | ||
|
||
def get_animals | ||
Pet.species.keys.to_h do |s| | ||
[s, authorized_scope(Pet.where(species: s).distinct.order(:breed), with: Organizations::AdoptablePetPolicy).pluck(:breed)] | ||
if current_user&.latest_form_submission | ||
@adoption_application = | ||
AdopterApplication.find_by( | ||
pet_id: @pet.id, | ||
form_submission_id: current_user.latest_form_submission.id | ||
) || | ||
@pet.adopter_applications.build( | ||
form_submission: current_user.latest_form_submission | ||
) | ||
end | ||
end | ||
end | ||
|
||
def set_likes | ||
likes = current_user.person.likes | ||
@likes_by_id = likes.index_by(&:pet_id) | ||
private | ||
|
||
def set_likes | ||
likes = current_user.person.likes | ||
@likes_by_id = likes.index_by(&:pet_id) | ||
end | ||
|
||
def set_species | ||
@species = params[:species] | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.