bigpotato
bigpotato

Reputation: 27507

Changing Rails 2 Routes to Rails 3 Routes

Hi I'm trying to change my routes from a rails 2 project to match the syntax in rails 3. How would I change this:

    map.connect "/stylesheets/:action.css", 
            :controller => "stylesheets", 
            :format => "css"

so that the :action can be matched to an action from the stylesheets controller? Would it be something like this?

match 'stylesheets/:action.css', :to => "stylesheets#{:action}"

Also, what is the syntax for :format in the routes for rails 3?

Upvotes: 0

Views: 44

Answers (2)

makaroni4
makaroni4

Reputation: 2281

I think it would be smth like:

match 'stylesheets/:action', :controller => :stylesheets, :defaults => { :format => :css }

or you can constraint your routes to .css format using :constraints => { :format => 'json' }

I recommend you to read through http://guides.rubyonrails.org/routing.html

Upvotes: 0

Benedikt Deicke
Benedikt Deicke

Reputation: 610

You're almost there with your solution. The only thing you have to change is the way you reference :action in the :to value.

match 'stylesheets/:action.css', :to => 'stylesheets#:action', :format => :css

As you can see, the syntax for :format didn't change.

Upvotes: 1

Related Questions