ruby on rails - STI and form_for problem -


I am using single table inheritance for managing various types of projects.

Model:

  class project & lt; ActiveRecord :: Base End Class SiteDesign & lt; Project & Class TechDesign & lt; End of the project  

Edit action with projects_controller:

  def edit @project = Project.find (params [: id]) end  

View edit.html.erb:

  & lt;% form_for (@project, url = & gt; {: Controller = & gt; "Projects", : Action => "Update"}). F | & Gt%; ... & lt;% = submit_tag 'Update'% & gt; & Lt;% end% & gt;  

Update actions of projects_controller:

  def update @project = Project.find (params [: id]) response_to do | Format | If @ project.update_attributes (params [: project]) @ project.type = params [: project] [: type] @ project.save flash [: notice] = 'The project was successfully updated.' Format.html {redirect_to (@project)} format.xml {head: ok} and format html {rendere: action = & gt; "Edit"} format.xml {render: xml = & gt; @ Project. Errors,: Status = & gt; : Unprocessable_entity} End End End  

Then I do some editing of the TechDesign entry on the editing scene and get the error:

  ProjectsController # update in NoMethodError One when you did not expect it, then the null object! You can have an example of ActiveRecord :: Base in the parameter it is clear that instead of the project parameter name, I have technical DIG parameters:  
  {"commit"}  

= & gt; "Update", "_method" = & gt; "Put", "authentication_token" = & gt; "Pd9mf7vbw + dv9mgwphe6bYwGDRJHEJ1x0RrG9hzirs8 =", "id" = & gt; "15", "tech_design" = & gt; {"Name" = & gt; "Ech", "concept" = & gt; "Efds", "type" = & gt; "TechDesign", "client_id" => "41", "description" = & gt; "Technology"}}

How to fix it?

The source of your problem is here: @project setting as a project of the TechDesign object .

  def edit @project = Project.find (params [: id]) end  

You can make sure that by specifying things you Want to work the way: project for name in form_for call.

  & lt;% form_for (: project, @project ,: url = & gt; {administrator = & gt; "projects" ,: action => "update"}) | F | & Gt%; ... & lt;% = submit_tag 'Update'% & gt; & Lt;% end% & gt;  

Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -