4

处理表单我有一个形式,我的档案编辑观点与此行的开头:与单表继承

<% form_for @profile, :html => { :multipart => true } do |f| %> 

资料进行单表继承和两个子类档案::艺术家和个人资料::监听器。

当我尝试访问编辑查看配置文件,我得到这个错误:

NoMethodError in Profiles#edit 

Showing /rubyprograms/dreamstill/app/views/profiles/edit.html.erb where line #1 raised: 

undefined method `profile_artist_path' for #<#<Class:0x103359a18>:0x1033560c0> 

,其中线1的代码,我上面贴在表格的行。我该如何解决这个错误?

UPDATE:

我将此代码添加到我的个人资料型号:

def self.inherited(child) 
    child.instance_eval do 
    def model_name 
     Vehicle.model_name 
    end 
    end 
    super 
end 

现在我的错误已更改为:

NameError in Profiles#edit 

Showing /rubyprograms/dreamstill/app/views/profiles/edit.html.erb where line #1 raised: 

uninitialized constant Profile::Vehicle 

更新2:

我改变表格的第一行为:

​​

,并提交按钮<%= f.submit :profile %>

现在我只是得到一个路线错误...

+0

'require'vehicle''? – lebreeze 2011-03-28 06:58:52

+0

http://stackoverflow.com/questions/5246767/sti-one-controller/5252136#5252136 – fl00r 2011-03-28 07:00:44

+0

此外,它仍然像一个路由错误:'undefined方法profile_artist_path' – lebreeze 2011-03-28 07:00:49

回答

3

VehileProfile

def self.inherited(child) 
    child.instance_eval do 
    def model_name 
     Profile.model_name 
    end 
    end 
    super 
end 

def self.model_name 
    name = "profile" 
    name.instance_eval do 
    def plural; pluralize; end 
    def singular; singularize; end 
    def i18n_key; singularize; end 
    def human(*args); singularize; end 
    end 
    return name 
end 

UPDATE

一个实际的问题是在形式。您应该添加:method => :put

<%= form_for(@profile, :html => { :multipart => true, :method => :put }) do |f| %> 
+0

nah配置文件是父类,而不是艺术家 – 2011-03-28 07:03:19

+0

确定然后使用配置文件 – fl00r 2011-03-28 07:03:41

+0

我要发布我的表单更改为... – 2011-03-28 07:05:11