Files
growstuff/app/controllers/alternate_names_controller.rb
google-labs-jules[bot] ac1463e2cf Add international alternate names for crops (#4132)
* I will add the international alternate names for the crops.

* Mark required

* Update factory

* Add placeholder

* Fix seeds

* Add language, though hardcoded to EN in most places

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2025-08-24 21:44:41 +09:30

63 lines
1.6 KiB
Ruby

# frozen_string_literal: true
class AlternateNamesController < ApplicationController
before_action :authenticate_member!, except: %i(index)
load_and_authorize_resource
respond_to :html, :json
responders :flash
# GET /alternate_names
# GET /alternate_names.json
def index
@alternate_names = AlternateName.all.order(:name).paginate(page: params[:page], per_page: 100)
respond_with(@alternate_names)
end
# GET /alternate_names/new
# GET /alternate_names/new.json
def new
@alternate_name = AlternateName.new
@crop = Crop.find_or_initialize_by(id: params[:crop_id])
end
# GET /alternate_names/1/edit
def edit; end
# POST /alternate_names
# POST /alternate_names.json
def create
params[:alternate_name][:creator_id] = current_member.id
@alternate_name = AlternateName.new(alternate_name_params)
if @alternate_name.save
redirect_to @alternate_name.crop, notice: 'Alternate name was successfully created.'
else
render action: "new"
end
end
# PUT /alternate_names/1
# PUT /alternate_names/1.json
def update
if @alternate_name.update(alternate_name_params)
redirect_to @alternate_name.crop, notice: 'Alternate name was successfully updated.'
else
render action: "edit"
end
end
# DELETE /alternate_names/1
# DELETE /alternate_names/1.json
def destroy
@crop = @alternate_name.crop
@alternate_name.destroy
redirect_to @crop, notice: 'Alternate name was successfully deleted.'
end
private
def alternate_name_params
params.require(:alternate_name).permit(:crop_id, :name, :creator_id, :language)
end
end