Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add custom path to resources route (only for one action)

I have below resource route

  resources :listings

This will have the path set to locahost:3000/listings/new

But how can I customise path to new action(only) to show like locahost:3000/listings/create_your_listing

or even(better if it can be customised like this)

locahost:3000/owners/create_your_listing

Only new action of the resources should be like that and rest as normal.. How can I achieve this?

like image 230
Abhilash Avatar asked Sep 19 '25 04:09

Abhilash


1 Answers

First,

resources :listings, except: :new

This will create listings resources except new.

next,

get "/owners/create_your_listing", to: "listings#new"

This will create the missing new route for your listing controller.

EDIT:

This may be the way to achieve custom path:(not tested)

scope(path_names: { new: 'create_your_listing'}) do
  resources :listing, path: 'listings'
end

Reference

like image 170
Sravan Avatar answered Sep 22 '25 00:09

Sravan