views:

33

answers:

2

Update : Gutted entire question with more thorough description

Ok same question with different names.

In my model, I do validate the presence of.

class QuickFact < ActiveRecord::Base
 belongs_to :organization

 validates_presence_of :quick_fact, :content

But if either is blank, it errors out with :

Missing template organizations/_quick_fact_fields.erb

Here's the catch. I have a nested form model with dynamically addable parts to it. As followed from here :

http://railscasts.com/episodes/197-nested-model-form-part-2

That is what generates and calls the _quick_fact_fields.erb . But that works perfectly and is located within quick_facts/_quick_fact_fields.html.haml

Update: My Controller Code

organizations_controller.rb

def update
  if @organization.update_attributes(params[:organization])
    ..
    elsif params[:organization][:quick_facts_attributes]
      flash[:notice] = 'QuickFacts successfully updated.'
      redirect_to organization_quick_facts_url(@organization)
    else
      flash[:notice] = 'Organization was successfully updated.'
      redirect_to :action => 'edit'
    end
  else
    # re-render last form
    ..
    elsif params[:organization][:quick_facts_attributes]
      render :template => "quick_facts/index"
    else
      render :action => 'edit'
    end
  end
end
+2  A: 

It seems that you're trying to render a my_custom_field partial from one of the worker views found in app/views/worker, but apparently there's no such partial there. If you show us the code of the relevant views and controllers, it will be easier to pinpoint the exact problem.

On a side note, you could simply do validates_presence_of :name instead of defining a custom validation method to simplify your model. However, this is likely unrelated to the error you're describing and is just a general improvement suggestion.

Pär Wieslander
Updated answer. :D Thanks for the reply.
Trip
Well, the same principle applies after your edits: You're trying to render the `quick_fact_fields` partial somewhere from an action in your `OrganizationsController`, so Rails goes looking for your partial in `app/views/organizations` rather than `app/views/quick_facts`. The problem lies within your view and/or controller code; if you post that code it'll be much easier to give a more detailed answer.
Pär Wieslander
A: 

Got it. I had two controllers.

quick_facts_controller.rb, and organizations_controller.rb

Once I deleted the update function in quick_facts_controller, it worked properly.

Trip