Search code examples
ruby-on-railsrubyruby-on-rails-3partialsnested-controls

How do I get render to work with nested controllers?


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?


Solution

  • 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.