Topic: respond_to in Rails 1.2.0rc1

Hi,

I want to use the respond_to function with the 1.2.0rc1 version of Rails.
My application skeletton was created with Rails 1.1.6.

The application I write should have a dynamically created sitemap. So I have this in my controller:

  def sitemap
    @articles = Article.find :all
    @tags = Article.tag_list.map {|tag| tag.name}
    respond_to do |format|
      format.html
      format.xml { render :type => :rxml }
    end   
  end

In the routes.rb I've added this line:
map.connect ':controller/:action/:id.:format'

When I want to view articles/sitemap action, I see what I want.
But when I go to articles/sitemap.xml I always get this error:

Routing Error
no route found to match "/articles/sitemap.xml" with {:method=>:get}

Has anybody an idea what I'm missing?

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: respond_to in Rails 1.2.0rc1

This is a complete guess as I haven't played around with format routing before. But, I wonder if it is expecting you to provide an "id' before you can use the format option like that? Try throwing an id in the URL to test this: /articles/sitemap/1.xml

Also, make sure you are running that version of rails by checkout out the properties: /rails_info/properties.

Railscasts - Free Ruby on Rails Screencasts

Re: respond_to in Rails 1.2.0rc1

You gave me the hint to the right way.
I had to add another route to my config:

map.connect ':controller/:action.:format'

I'm wondering why they show it here this way:

class WeblogController < ActionController::Base
  def index
    @posts = Post.find :all
    respond_to do |format|
      format.html
      format.xml { render :xml => @posts.to_xml }
      format.rss { render :action => "feed.rxml" }
    end
  end
end

GET /weblog     # returns HTML from browser Accept header
GET /weblog.xml # returns the XML
GET /weblog.rss # returns the RSS


Quote:
That is the magic of :format. All new applications will have one additional default route: map.connect ':controller/:action/:id.:format'. With this route installed, imagine the following example:

Last edited by Dieter Komendera (2006-12-03 16:47:36)

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: respond_to in Rails 1.2.0rc1

Sounds like a bug. You might want to open a ticket on it if there isn't one already. I'm glad that route works though.

Railscasts - Free Ruby on Rails Screencasts

Re: respond_to in Rails 1.2.0rc1

Pretty sure, at least from what ive seen of 1.2RC1, you'll want map.resource instead of map.connect

Just a thought.

Re: respond_to in Rails 1.2.0rc1

Although map.resource is a new addition in 1.2, in this case map.connect is the proper method to use.

Railscasts - Free Ruby on Rails Screencasts