-1

These are my routes:

resources :auctions do
  resources :bids
end

I have the auctions#show view with a form for bids:

= form_for [@auction, @bid] do |form|
  = form.input :maximum
  = form.button :submit

This of course POST to auctions/:auction_id/bids.

I have this bids#create action:

def create
  #...some_logic...
  if @bid.save
    #...happy_face...
  else
    # See Below
  end
end

In this "if the bid didn't save logic" I have:

render 'auctions/show'

This should (and does) try to render the app/views/auctions/show.html.erb but I get this error:

Missing partial bids/info-panel, application/info-panel with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
    * "app/views"
    * "gems/devise-2.0.4/app/views"

Obviously this is a problem! It's looking in app/views/bids instead of app/views/auctions for the partials.

How do I make the context be app/views/auctions for those partials?

krainboltgreene
  • 1,841
  • 2
  • 17
  • 25

2 Answers2

1

Something like this should do it:

<%= render :partial => "auctions/info-panel" %>

If you don't include the leading directory, it assumes the current directory.

Benjamin Cox
  • 6,090
  • 21
  • 19
  • I'm not willing to change ALL the partial calls in `app/views/auctions/show.html.erb` to specify the auctions directory. That seems silly and very not DRY. – krainboltgreene May 13 '12 at 23:41
  • In addition, any *_path methods wont work as they're in the context of `auctions/:auction_id/bids` route. – krainboltgreene May 13 '12 at 23:59
1

Since this is an error condition, why dont you redirect to auctions/show action instead of rendering its template. You can pass error metadata with your redirect, so that auctions/show action knows that its an error state and renders the form accordingly.

Vlad Gurovich
  • 8,463
  • 2
  • 27
  • 28
  • Yeah, I heavily considered that (and I think I'll probably do it), but the app I'm dealing with doesn't make it that easy :( Marking yours as the answer anyhow. – krainboltgreene May 14 '12 at 20:36