我有一个包含名为typename
的varchar字段的简单表。它的定义如下:
CREATE TABLE public.ref_community_types
(
id integer NOT NULL DEFAULT nextval('ref_community_types_id_seq'::regclass),
typename character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
CONSTRAINT ref_community_types_pkey PRIMARY KEY (id)
)
我想通过我的REST API对该表中的所有行运行一个简单的GET,但是我收到了这500个错误:
RefCommunityType Load (2.5ms) SELECT "ref_community_types".* FROM "ref_community_types"
Rendered ref_community_types/_ref_community_type.json.jbuilder (48.6ms)
Rendered ref_community_types/index.json.jbuilder (68.2ms)
Completed 500 Internal Server Error in 204ms (ActiveRecord: 5.0ms)
ActionView::Template::Error (undefined method `type' for #<RefCommunityType:0x00000007068270>):
1: json.extract! ref_community_type, :id, :type, :created_at, :updated_at
2: json.url ref_community_type_url(ref_community_type, format: :json)
app/views/ref_community_types/_ref_community_type.json.jbuilder:1:in `_app_views_ref_community_types__ref_community_type_json_jbuilder__1812723856_58877260'
app/views/ref_community_types/index.json.jbuilder:1:in `_app_views_ref_community_types_index_json_jbuilder__546876462_59109520'
我的浏览器返回以下内容:
Request URL:http://localhost:3000/ref_community_types
Request Method:GET
Status Code:500 Internal Server Error
我查看了可能导致此问题的所有典型位置(routes.rb
,models/ref_community_type.rb
,controllers/ref_community_types_controller.rb
,migrate/[date]_create_ref_community_types.rb
),但它们都包含名称{{1 }}
我还能在哪儿看?我正在对“类型”一词进行搜索,但它非常通用,我的搜索结果会返回很多不相关的结果。
答案 0 :(得分:1)
在app/views/ref_community_types/_ref_community_type.json.jbuilder
中,将type
更改为typename