docbrown/app/controllers/concerns/classified_listings_toolkit.rb
Mario See 11be56f38c Add location to listings (#3370)
* add location to classified_listings

create rails migration and ran rake db:migrate

* add faker city to seed

* add location to index json

* add location as searchable attribute in algolia

* add form text field for adding location to new listing

* add location to dashboard json

* add location field for editing listings

* add location to listing_params in controller

* add location to single listing view

* add location to listing row in dashboard

* add location to dashboard test

* adjust listing dashboard row spacing

* reduce character limit

* reduce lines of conditional html elements

* compress listing card const

* fix form call for location in edit page

* update snapshot in dashboard

* add location length validation in listing model

* shorten limit and update location in edit page
2019-07-10 12:45:41 -04:00

36 lines
1.2 KiB
Ruby

module ClassifiedListingsToolkit
extend ActiveSupport::Concern
def unpublish_listing
@classified_listing.published = false
@classified_listing.save
@classified_listing.remove_from_index!
end
def publish_listing
@classified_listing.published = true
@classified_listing.save
@classified_listing.index!
end
def update_listing_details
@classified_listing.title = listing_params[:title] if listing_params[:title]
@classified_listing.body_markdown = listing_params[:body_markdown] if listing_params[:body_markdown]
@classified_listing.tag_list = listing_params[:tag_list] if listing_params[:tag_list]
@classified_listing.category = listing_params[:category] if listing_params[:category]
@classified_listing.location = listing_params[:location] if listing_params[:location]
@classified_listing.contact_via_connect = listing_params[:contact_via_connect] if listing_params[:contact_via_connect]
@classified_listing.save
end
def bump_listing
@classified_listing.bumped_at = Time.current
saved = @classified_listing.save
@classified_listing.index! if saved
saved
end
def clear_listings_cache
ClassifiedListings::BustCacheJob.perform_now(@classified_listing.id)
end
end