I am trying to setup a new static and later dynamic page.
Inside app/controllers/
I created detailpages_controller.rb
. Inside I have:
class DetailPagesController < ApplicationController
def show
render
end
end
Then, on config/routes.rb
I have:
Rails.application.routes.draw do
root 'welcome#index'
DetailPagesController.action_methods.each do |action|
get "/#{action}", to: "detailpages##{action}", as: "#{action}_page"
end
end
On app/viewes/pages
there is a detailpages.html.erb
file that just contains a <h2>Hello World</h2>
When I go to http://localhost:3000/detailpages.html
I get:
No route matches [GET] "/detailpages.html"
if I just do localhost:3000
my index.html
works perfectly fine but I can't, for my life, add this new page so I can later link to it.
Could someone please tell me what I'm doing wrong?
You can map to the detailpages.html
with
get 'detailpages.html' => 'detail_pages#show', as: :detail_page
Also you need to edit the name of your DetailPagesController
, it should be detail_pages_controller.rb
. Every word is separated with _
, called snake casing.
You will also need a corresponding view, placed in app/views/detail_pages/show.html.erb