问题
I'm trying to set up some semistatic page in a rails 3 app I've created a Pages controller with some non restful actions
class PagesController < ApplicationController
def home
end
def about
end
def contact
end
def monday
end
def saturday
end
def sunday
end
end
It's showing at /pages/home etc. Is there a way to re-route the pages so that they show under /home etc.
I've tried
resources :pages, :path => '/' do
#blah
end
but I get an error message telling me that the :action => show is missing. Is it possible to apply a setting to all non restful actions?
回答1:
You could add collection routes:
resources :pages do
collection do
get 'home'
get 'about'
get 'contact'
...
end
end
来源:https://stackoverflow.com/questions/8946181/rails-3-removing-controller-name-form-url