1

Error: Template is missing

Missing template miscellaneous/sitemap, application/sitemap with {:locale=>[:en], :formats=>[:xml], :handlers=>[:erb, :builder]}. Searched in: * "/Users/yliu/Google Drive/ruby projects/Blog/lenswish/app/views" * "/usr/local/rvm/gems/ruby-1.9.3-p194/bundler/gems/twitter-bootstrap-rails-4b8a511e6518/app/views" * "/usr/local/rvm/gems/ruby-1.9.3-p194/gems/devise-3.1.0/app/views"

rake routes:

GET      /sitemap.xml(.:format)                 miscellaneous#sitemap {:format=>"xml"}

routes.rb:

get "sitemap.xml", :to => "miscellaneous#sitemap", defaults: { format: "xml" }

controller:

class MiscellaneousController < ApplicationController
  def sitemap
    @card_templates = CardTemplate.all
    respond_to do |format|
      format.xml
    end
  end
end

Template position: app/views/miscellaneous/sitemap.xml.builder

content in template sitemap.xml.builder:

# Sitemaps 0.9 XML format: http://www.sitemaps.org/protocol.php
xml.instruct!
xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
  xml.url do
    xml.loc root_url
    xml.changefreq 'daily'
    xml.lastmod @card_templates.first.updated_at.iso8601
    xml.priority '0.8'
  end
end

I already checked file permission issues. Still not working. Anyone help please. Thanks in advance.

Tristan.Liu
  • 176
  • 1
  • 7

2 Answers2

0

This looks wrong to me:

GET      /sitemap.xml(.:format)                 miscellaneous#sitemap {:format=>"xml"}

Shouldn't it be like this?

GET      /sitemap(.:format)                 miscellaneous#sitemap {:format=>"xml"}

I would change your route to:

get "sitemap", :to => "miscellaneous#sitemap"

Your controller code should look about the same

class MiscellaneousController < ApplicationController
  def sitemap
    @card_templates = CardTemplate.all
    respond_to do |format|
      format.xml
    end
  end
end
Farley Knight
  • 1,795
  • 1
  • 13
  • 17
  • Made some more changes. Let me know if that helps. – Farley Knight Nov 27 '13 at 02:29
  • Still getting the same error. More info: I am on ruby 1.9.3 rails 3.2.13. Thanks. – Tristan.Liu Nov 27 '13 at 02:36
  • Found a solution. Updated answer and pushed example to github: https://github.com/farleyknight/sample_app – Farley Knight Nov 27 '13 at 02:49
  • Thanks, Farley. Your app works as expected.It's weird. I used the same code to create a fresh app, which works fine. While the same code broke in my existing app. It might be some configuration issue? – Tristan.Liu Nov 27 '13 at 04:45
  • I tried render(:template => "miscellaneous/sitemap", :formats => [:xml], :handlers => :builder, :layout => false), but still got the same problem. – Tristan.Liu Nov 27 '13 at 17:45
0

This turns out to be an IDE issue, the file name I saw from the textmate ui differs from what I saw from the terminal. Fixed after I renamed the file.

Tristan.Liu
  • 176
  • 1
  • 7