This commit is contained in:
Daniel O'Connor
2025-09-20 09:43:22 +00:00
parent 6df1d9d247
commit 54acc369ab
11 changed files with 27 additions and 23 deletions

View File

@@ -67,16 +67,14 @@ class ActivitiesController < DataController
end
def update
if @activity.update(activity_params)
if activity_params[:finished].present?
link = new_activity_path(
name: @activity.name,
garden_id: @activity.garden_id,
planting_id: @activity.planting_id,
due_date: 2.weeks.from_now.to_date
)
flash[:notice] = t('activities.finished_prompt_html', link: link).html_safe
end
if @activity.update(activity_params) && activity_params[:finished].present?
link = new_activity_path(
name: @activity.name,
garden_id: @activity.garden_id,
planting_id: @activity.planting_id,
due_date: 2.weeks.from_now.to_date
)
flash[:notice] = t('activities.finished_prompt_html', link: link).html_safe
end
respond_with @activity
end

View File

@@ -83,11 +83,9 @@ class PlantingsController < DataController
end
def update
if @planting.update(planting_params)
if planting_params[:finished].present? && @planting.garden.plantings.current.empty?
link = new_activity_path(name: 'Cultivate soil', garden_id: @planting.garden_id)
flash[:notice] = t('plantings.finished_prompt_html', link: link).html_safe
end
if @planting.update(planting_params) && planting_params[:finished].present? && @planting.garden.plantings.current.empty?
link = new_activity_path(name: 'Cultivate soil', garden_id: @planting.garden_id)
flash[:notice] = t('plantings.finished_prompt_html', link: link).html_safe
end
respond_with @planting
end

View File

@@ -13,7 +13,7 @@ module AutoSuggestHelper
resource = resource.class.name.downcase
source_path = Rails.application.routes.url_helpers.send("search_#{source}s_path", format: :json)
%(
<input id="#{source}" class="auto-suggest #{options[:class]}" #{options[:required] ? 'required="required"' : ''}
<input id="#{source}" class="auto-suggest #{options[:class]}" #{'required="required"' if options[:required]}
type="text" value="#{default}" data-source-url="#{source_path}",
placeholder="e.g. lettuce">
<noscript class="text-warning">

View File

@@ -7,8 +7,8 @@ module EventHelper
def event_description(event)
render "#{event.event_type.pluralize}/description", event_model: resolve_model(event)
rescue ActionView::MissingTemplate
"#{event.event_type.humanize.downcase}d"
rescue ActionView::MissingTemplate
"#{event.event_type.humanize.downcase}d"
end
def resolve_model(event)

View File

@@ -3,6 +3,7 @@
class Forum < ApplicationRecord
extend FriendlyId
include Ownable
validates :name, presence: true
validates :description, presence: true
friendly_id :name, use: %i(slugged finders)

View File

@@ -2,6 +2,7 @@
class GardenType < ApplicationRecord
extend FriendlyId
friendly_id :name, use: %i(slugged finders)
has_many :gardens, dependent: :nullify

View File

@@ -2,12 +2,14 @@
class Member < ApplicationRecord
include Discard::Model
acts_as_messageable # messages can be sent to this model
include Geocodable
include MemberFlickr
include MemberNewsletter
extend FriendlyId
friendly_id :login_name, use: %i(slugged finders)
#
@@ -105,9 +107,10 @@ class Member < ApplicationRecord
uniqueness: {
case_sensitive: false
}
validates :website_url, format: { with: /\Ahttps?:\/\//, message: "must start with http:// or https://" }, allow_blank: true
validates :other_url, format: { with: /\Ahttps?:\/\//, message: "must start with http:// or https://" }, allow_blank: true
validates :instagram_handle, :facebook_handle, :bluesky_handle, format: { without: %r{\Ahttps?:\/\/|\/}, message: "should be a handle, not a URL" }, allow_blank: true
validates :website_url, format: { with: %r{\Ahttps?://}, message: "must start with http:// or https://" }, allow_blank: true
validates :other_url, format: { with: %r{\Ahttps?://}, message: "must start with http:// or https://" }, allow_blank: true
validates :instagram_handle, :facebook_handle, :bluesky_handle,
format: { without: %r{\Ahttps?://|/}, message: "should be a handle, not a URL" }, allow_blank: true
#
# Triggers

View File

@@ -2,6 +2,7 @@
class PlantPart < ApplicationRecord
extend FriendlyId
friendly_id :name, use: %i(slugged finders)
has_many :harvests, dependent: :destroy

View File

@@ -2,6 +2,7 @@
class Role < ApplicationRecord
extend FriendlyId
friendly_id :name, use: %i(slugged finders)
validates :name, uniqueness: true, presence: true

View File

@@ -6,6 +6,7 @@ class Seed < ApplicationRecord
include Finishable
include Ownable
include SearchSeeds
friendly_id :seed_slug, use: %i(slugged finders)
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze
@@ -48,7 +49,7 @@ class Seed < ApplicationRecord
"are heirloom, hybrid, or unknown" }
validates :source, allow_blank: true,
inclusion: { in: SOURCE_VALUES, message: "You must say where the seeds are from," \
"or that you don't know" }
"or that you don't know" }
#
# Delegations

View File

@@ -3,7 +3,7 @@
class BaseResource < JSONAPI::Resource
abstract
[:create, :update, :remove].each do |action|
%i(create update remove).each do |action|
set_callback action, :before, :authorize
end