AdamGol
AdamGol

Reputation: 13

How to skip the name of folder in routes path in Rails?

I'm building a frontend part in my rails app. The controllers like posts, comments, etc., will be in a folder I named it public. Therefore, the folders of posts in view is inside public folder as well, but I would like routes come after the root like:

localhost:3000/posts

NOT: localhost:3000/public/posts

It means I would like to skip public folder in routes.

Upvotes: 1

Views: 287

Answers (1)

Arslan Ali
Arslan Ali

Reputation: 17802

In your routes file, you can write the following:

scope module: 'public' do
  resources :posts
end

Now, it will generate routes without the word public.

Not, for it to work, PostsController must be inside a folder name: public, and its name should be something like following:

class Public::PostsController < ApplicationController
end

Upvotes: 1

Related Questions