Yannick Schall
Yannick Schall

Reputation: 34969

rails 3 removing controller name form url

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?

Upvotes: 0

Views: 512

Answers (1)

patrickmcgraw
patrickmcgraw

Reputation: 2495

You could add collection routes:

resources :pages do
  collection do
    get 'home'
    get 'about'
    get 'contact'
    ...
  end
end

Upvotes: 1

Related Questions