Я использую Rails Api. В таблице «attribute» в поле «attribute_type» используются числа. Я хочу заменить эти цифры определенными словами. Для этого я делаю следующее:
attributes_controller.rb:
class AttributesController < ApplicationController
before_action :set_attribute, only: [:show, :update, :destroy]
def index
@attributes = Attribute.all
render json: @attributes
end
def show
render json: @attribute
end
def create
@attribute = Attribute.new(attribute_params)
if @attribute.save
render json: @attribute, status: :created, location: @attribute
else
render json: @attribute.errors, status: :unprocessable_entity
end
end
def update
if @attribute.update(attribute_params)
render json: @_attribute
else
render json: @attribute.errors, status: :unprocessable_entity
end
end
def destroy
@attribute.destroy
end
private
def set_attribute
@attribute = Attribute.find(params[:id])
end
def attribute_params
params.require(:attribute).permit!
end
end
attribute.rb:
class Attribute < ActiveRecord::Base
extend ActiveHash::Associations::ActiveRecordExtensions
self.table_name = 'ATTRIBUTS'
self.primary_key = 'attribut_id'
belongs_to :attribute_type, foreign_key: 'attribut_type'
end
attribute_type.rb:
class AttributeType < ActiveHash::Base
include ActiveHash::Associations
has_many :attributes, foreign_key: 'attribut_type'
self.data = [
{id: 0, name: 'Text', type: 'text'},
{id: 1, name: 'Date', type: 'date'},
{id: 2, name: 'Number', type: 'number'}
]
end
routes.rb:
Rails.application.routes.draw do
resources :attributes do
collection do
get 'attribute_type'
end
end
end
Что не сделано или что недостаточно для замены чисел словами из модели "attribute_type"?
Когда я пытаюсь перейти по этому URL /attributes/attribute_type
, возникает эта ошибка:
AbstractController :: ActionNotFound (Действие 'attribute_type'
не удалось найти для AttributesController):