Cam Norgate
Cam Norgate

Reputation: 630

Missing partial when using devise 2.0 w Rails 3.1.3

I have a rails app (rails 3.1.3) that has a shopping cart model. I wanted to show a summary of the shopping cart in the layout so I created the partial views/carts/_cart.html.haml. My app was working fine and rendering the cart partial in every view. But when I installed devise 2.0, the partial could no longer be found for devise views. Instead, I would see the following error code when I tried to call a devise view:

ActionView::Template::Error (Missing partial views/carts/cart with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
  * "/Users/cameronnorgate/Web Development/Practice Apps/1-Camerons Tea/pgktea/app/views"
  * "/Users/cameronnorgate/.rvm/gems/ruby-1.9.2-p290@pgktea/gems/devise-2.0.4/app/views"

As you can see, it searches for the partial in app/views, but doesn't go all the way into the 'carts' folder in order to find the 'cart' partial. This is weird, because the code I had in the layout view specified the exact path (see below):

%body{:class => params[:controller]}
  .master_container
    .master_header
      .inner_header
        .cart
          = render :partial => 'views/carts/cart', :object => @cart 

Can anyone help me understand why my call to render the partial is not being found when inside a devise view?

The short term fix I've made for this is to bring the partial code back into the full layout file - so now devise doesn't have to go searching and everything works... but that's not ideal and it's cluttering up my code.

Thanks!

Upvotes: 1

Views: 1485

Answers (2)

Arpit Vaishnav
Arpit Vaishnav

Reputation: 4780

If this page can be access from other pages . then

= render :partial => '/carts/cart', :object => @cart

Is the correct way , because if this page open in other models then 'carts/cart' will not be available like if url is ex. 'localhost:3000/products' this page will give missing partial error so / will solve the issue and as other answers, 'views' is not needed

Upvotes: 1

kafuchau
kafuchau

Reputation: 5593

You should be able to specify the partial with just:

= render :partial => 'carts/cart', :object => @cart

The views/ part of your definition is probably throwing it off. app/views is implied, so when you specify views/carts/cart, it's probably not finding a views directory under app/views.

Upvotes: 2

Related Questions