Single table overlay machining forms

I have a form in my profile edit view starting from this line:

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

A profile is subjected to single inheritance on a page, and two subclasses are the profile :: Artist and Profile :: Listener.

When I try to access the edit view for a profile, I get this error:

 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> 

where line 1 is the line of code for the form I posted above. How can I fix this error?

UPDATE:

I added this code to my profile model:

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

And now my error has changed to:

 NameError in Profiles#edit Showing /rubyprograms/dreamstill/app/views/profiles/edit.html.erb where line #1 raised: uninitialized constant Profile::Vehicle 

UPDATE 2:

I changed the first line of the form to:

 <% form_for(:profile, @profile, :url => {:controller => "profiles", :action => "update"}, :html => { :multipart => true }) do |f| %> 

and submit button on <%= f.submit :profile %>

Now I just get the routes error ...

+4
source share
1 answer

Not Vehile , but Profile !

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

or

 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

The actual problem was in shape. You must add :method => :put

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

Source: https://habr.com/ru/post/1345506/


All Articles