rails 3 removing controller name form url

穿精又带淫゛_ 提交于 2019-12-13 21:15:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!