0
我有一個簡單的表,其中包含一個名爲typename
的varchar字段。它的定義如下:REST API返回模型undefined方法錯誤
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
典型的斑點)但它們都包含名稱typename
。
我還能在哪裏看?我正在對「類型」這個術語進行搜索,但它非常通用,我的搜索結果返回了很多無關的結果。
它看起來像'_ref_community_type.json.jbuilder'試圖調用''上RefCommunityType' type'。你檢查過了嗎? – jvillian