Heartcroft
Heartcroft

Reputation: 1712

Rails: render template looking for the wrong partial

I have a TasksController, and a SubtasksController. In a given moment of an action from SubtasksController I want to:

# app/controllers/tasks_controllers.rb
render 'tasks/index' # Or: render template: 'tasks/index'

When that action is called from the view though, it appears rails is trying to render the wrong partial:

ActionView::Template::Error (Missing partial subtasks/tasks, private_area/tasks, application/tasks with {:locale=>[:ca, :es], :formats=>[:js, :html], :handlers=>[:erb, :builder, :slim, :jbuilder, :coffee, :haml]}. Searched in:
  * "/Users/****/app/views"

I really don't understand what's going on here, any thoughts?

Upvotes: 3

Views: 1140

Answers (1)

Matt
Matt

Reputation: 14038

When you render another controllers action the page that is displayed will look in the calling controllers views for any partials within itself.

You can get around this by explicitly declaring the path to partials within the page so that even when called from another controller it will always look in the right place.

# tasks/index page 
<%= render 'tasks/some_partial' %>

Now no matter which controller renders this page it will always look in tasks for its partials.

Upvotes: 7

Related Questions