Search code examples
ruby-on-railsruby-on-rails-4controllers

Controller actions for home, about and contact pages


I've just started a project and created a pages_controller and within the controller I have this:

class PagesController < ApplicationController

def home

end

end

these are my routes:

  devise_for :users
  root to: "pages#home"

I created the pages controller thinking I can use it to have a home page, about page & contact page. From my limited experience, it seems that your actions within your controllers should stick to the new,create,destroy,delete,show,index,edit and update Is it bad to name an action Home, contact or about like I've done above? What do you usually do?


Solution

  • There is nothing wrong with not having 100% RESTful routes in a Rails application. Particularly for your exact use case, which is to collect a handful of "static" pages. You're absolutely on the right track. The only thing I would consider changing would be to break out the contact page to its own controller (ContactPageSubmissions, perhaps), if it has a form on it - if it is just contact information, I would leave that where it is, too.