views:

209

answers:

3

I am using formatastic in a HAML form.

- semantic_form_for @company do |f|
  - f.inputs do
    = f.input :description 
    = f.input :type 
    = f.input :industry 
    = f.input :hq 
    = f.input :products 
    = f.input :subsidiaries 
    = f.input :employees 
    = f.input :revenue 
    = f.input :net_income 
  = f.buttons 

When ever I try to save an existing record I get an error.

Template is missing
Missing template companies/update.erb in view path app/views

I recently migrated the form from ERB to HAML. The form used to work in ERB.

How do I fix this issue?

Edit

I resolved the issue. It is not related to HAML or Formtastic. I was passing a block to the save method and that caused the issue. See my answer down below for details.

+1  A: 

Did you install the Rails' plugin for Haml?

John Topley
A: 

Rails is looking for a view file in app/views/companies/ called update.something.erb (probably update.html.erb). My guess is you've got an update.html.haml file instead, so this is why you're getting the error.

Either way, this has nothing to do with Formtastic sorry.

What files do you have listed in app/views/companies ?

Justin French
I resolved the issue. It is not related to HAML or Formtastic. I was passing a block to the save method and that caused the issue. See my answer down for details.
KandadaBoggu
+1  A: 

I found the reason for this error. I reused some code in the controller from another project where I used OAuth plugin. The OAuth plugin requires you to pass a block to the ActiveRecord save method. The vanilla ActiveRecord save doesn't support blocks. Once I removed the blocks everything works. Original code:

  def update
    @company.attributes = params[:company]
    @company.save do |result|
      if result
        flash[:notice] = "Successfully updated company."
        redirect_back_or_default root_url
      else
        render :action => 'edit'
      end
    end
  end

Some reference material:

Article 1

Article 2

KandadaBoggu