문제

I am try to convert an older DSL style routes.rb file in a project I am working on to the new DSL style used in Rails 3. Since most of it consists of regular routes, the conversion seems simple. Most of it just goes like:

RailsRoot::Application.routes.draw do |map|
  root :to => "index#index"
  match '/table/create' => "table#create"
  match '/table/delete' => "table#delete"

  # A bunch more of similar match statements

  map.js ':controller/:action.:format'
end

I've been following the documentation at engine yard to do the conversion. If I am reading it right, it looks like to me I should be able to just remove the surrounding draw do |map| code and since under the new DSL, the :to tag seems to be assumed unless stated otherwise, the match statements should be able to be left as is and work. (However, I could be entirely wrong in my assumption and possibly have that be my main problem.)

The issue I think I am having is when I get down to that line that says map.js ':controller/:action.:format', I have no clue how to convert that for the Rails 3 style DSL for routing. How would I go about converting this?

Edit #1:

I just ran rake routes after converting it with Iuri G's comment suggestion, and it's actually complaining about root not being defined. So Iuri G probably gave me the correct solution, but I need to solve this other problem first before I can verify it.

Edit #2:

I am an idiot for not realizing this. Since all the example code I saw excluded this part, I thought I didn't need it anymore. However, what I was missing was this line: RailsRoot::Application.routes.draw do and then having the rest of the routes inside the block. I feel really silly right now. Anyways, Iuri G was right on the money. Thanks a bunch!

도움이 되었습니까?

해결책

As luri G. stated earlier, the correct way to convert it is by changing it to:

match ':controller(/:action(/:id))(.:format)'

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top