我的个人资料编辑视图中有一个表单,从此行开始:
<% form_for @profile, :html => { :multipart => true } do |f| %>
配置文件经历单表继承,两个子类是Profile :: Artist和Profile :: Listener。
当我尝试访问配置文件的编辑视图时,出现此错误:
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行是我在上面发布的表单的代码行。我该如何解决这个错误?
更新:
我将此代码添加到我的个人资料模型中:
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:
我将表单的第一行更改为:
<% form_for(:profile, @profile, :url => {:controller => "profiles", :action => "update"}, :html => { :multipart => true }) do |f| %>
和<%= f.submit :profile %>
的提交按钮
现在我刚收到路线错误......
答案 0 :(得分:3)
不是Vehile
而是Profile
!
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
<强>更新强>
实际问题出在形式上。您应该添加:method => :put
<%= form_for(@profile, :html => { :multipart => true, :method => :put }) do |f| %>