Jonathan Allard
Jonathan Allard

Reputation: 19249

ActionView::MissingTemplate after Rails 3.1 upgrade

After upgrading to Rails 3.1.0 and following David Rice's instructions, all of my controllers strangely can't find their views anymore.

# rails s #

Started GET "/units" for 127.0.0.1 at 2011-09-04 07:52:23 -0400
  Unit Load (0.1ms)  SELECT "units".* FROM "units" 

ActionView::MissingTemplate (Missing template units/index, application/index with {:handlers=>[:erb, :builder], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
):
  app/controllers/units_controller.rb:9:in `index'

units_controller.rb:

  # GET /units
  # GET /units.xml
  def index
    @units = Unit.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @units }
    end
  end

Of course, the view is there (/app/views/units/index.html.erb; it was working before the upgrade). I feel this is a stupid error, what am I missing here?

Upvotes: 7

Views: 4788

Answers (7)

robd
robd

Reputation: 9825

I saw this problem because some of my templates were still named .rhtml instead of .erb.html

Upvotes: 0

xnzac
xnzac

Reputation: 341

If you're upgrading an old app that's been around since Rails v1, you might have xml templates named as .rxml. This is no longer supported in Rails 3.1(where it was in 3.0), so they need to be renamed to .builder.

What was:

units.xml.rxml

Needs to be renamed to:

units.xml.builder

This would affect all templates that uses the XML builder. e.g. RSS, KML etc.

Upvotes: 0

Buminda
Buminda

Reputation: 621

rails generate controller Welcome index will generate the controller , I guess this is the easiest way to generate the controller

Upvotes: 0

Ashley Raiteri
Ashley Raiteri

Reputation: 710

I got the same error, but for a different reason. I had my RAILS_ENV set to development when I ran my cucumber tests.

export RAILS_ENV= or export RAILS_ENV=test fixed the problem.

Upvotes: 0

Jonathan Allard
Jonathan Allard

Reputation: 19249

Like Tom said, I had originally forgotten to remove

config.action_view.debug_rjs = true

in /config/environments/development.rb, but at the time I posted the question, I had done it already.

The thing though (quite stupid) is that I had to restart the server after changing a config parameter. Restart your servers when you change your config settings, kids!

Upvotes: 2

Tom de Vries
Tom de Vries

Reputation: 146

It looks like you forgot to remove the following line in your development.rb:

config.action_view.debug_rjs = true

This should be removed or commented out when not using Rail Javascript.

See the "jQuery: New Default" on rubyonrails.org for more information on upgrading http://weblog.rubyonrails.org/2011/4/21/jquery-new-default

Upvotes: 4

snowangel
snowangel

Reputation: 3462

The views are saved as erb, not haml? Just stabbing in the dark...

Upvotes: 0

Related Questions