Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails is Looking for a Partial in the Wrong Directory

I have a polymorphic Review model. The namespaced model User::Library::Publication is reviewable. The reviews are created properly, but when I try to display them through a partial, Rails looks up the wrong directory.

In my view:

<%= render @review %>

I get this error:

Missing partial user/library/reviews/review with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder]}

Rails is apparently looking for the review partial within the namespace's directory views/user/library instead of the /views/reviews. Any idea why this is happening?

like image 428
nullnullnull Avatar asked Apr 08 '13 17:04

nullnullnull


1 Answers

If you want to remove namespacing from the partial template path, you can set the prefix_partial_path_with_controller_namespace variable in your config/application.rb:

# config/application.rb
config.action_view.prefix_partial_path_with_controller_namespace = false

This will load partial paths as you define them (without the namespace).

You can see the original Pull Request here.

like image 144
Richard Peck Avatar answered Sep 29 '22 07:09

Richard Peck