【发布时间】:2011-03-28 17:20:30
【问题描述】:
我的个人资料编辑视图中有一个以该行开头的表单:
<% form_for @profile, :html => { :multipart => true } do |f| %>
Profile 进行单表继承,两个子类是 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 %>
现在我只是得到一个路由错误...
【问题讨论】:
-
另外它似乎仍然是一个路由错误:
undefined method profile_artist_path -
糟糕,应该是个人资料
标签: ruby-on-rails ruby ruby-on-rails-3 routing single-table-inheritance