轨道4 simple_form belongs_to的关联未定义的方法错误 [英] rails 4 simple_form belongs_to association undefined method error

查看:122
本文介绍了轨道4 simple_form belongs_to的关联未定义的方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从对象文件::文件使用Rails 4,当我想呈现的一种形式(与simple_form)我有这样的错误:未定义的方法document_type_id的#<文件::文件:0x007fada4a50240>

Using rails 4, when I want to render a form (with simple_form) from an object Document::Document I have this error: undefined method document_type_id for #<Document::Document:0x007fada4a50240>

下面我的模型的一部分​​:

Here a part of my model:

class Document::Document < ActiveRecord::Base
   ...
   belongs_to :document_type, -> {include(:translations)}, :class_name => 'Document::Type'
   ...
end

该方法新我控制器:

The method new of my controller:

def new
   @document = Document::Document.new
end

和与simple_form形式的一部分:

And a part of the form with simple_form:

=f.association :document_type, prompt: t('document.documents.form.choose_document_type'), collection: Document::Type.includes(:translations)

错误:

undefined method `document_type_id' for #<Document::Document:0x007fada4a50240>
Extracted source (around line #14):

   11    .row
   12      =f.input :language, collection: languages_list, prompt: t("document.documents.form.choose_language"), label_html: tooltip(t('document.documents.forms.tooltips.language')), wrapper_html: {class: 'columns large-4'}, input_html: {class: 's2'}
   13      =f.input :study_level, prompt: t('document.documents.form.choose_study_level'), label_html: tooltip(t('document.documents.forms.tooltips.study_level')), wrapper_html: {class: 'columns large-4'}, input_html: {class: 's2'}
   14      =f.association :document_type, prompt: t('document.documents.form.choose_document_type'), collection: Document::Type.includes(:translations), label_html: tooltip(t('document.documents.forms.tooltips.type')), wrapper_html: {class: 'columns large-4'}, input_html: {class: 's2'}
   15      -#=f.association :domains, collection: Domain.includes(:translations).order('name ASC'), label_html: tooltip(t('document.documents.forms.tooltips.domains')), input_html: {class: 's2'}
   16    .form-actions
   17       =f.button :submit, t('document.documents.form.submit') 

为什么这个错误?

Why this error ?

我从轨3.2升级。之前一切都很正常。

I upgraded from rails 3.2. Before everything works great.

在轨3.2我补充说:

attr_accessible :document_type_id, ...

也许错误是从那里来了

Maybe the error is coming from there

推荐答案

抱歉不便。

这是一个问题的迁移。别人改变了迁移文件和现场 document_type_id 没了present在数据库中的表。

It was an issue with migration. Someone else changed the migration file and the field document_type_id was no more present in the table of the database.

我花了一段时间,直到我发现这个愚蠢的问题。

It took me a while until I find this stupid issue.

感谢您的答复,并表示歉意。

Thanks for the reply and apologise

这篇关于轨道4 simple_form belongs_to的关联未定义的方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆