Amit
Amit

Reputation: 539

Rails: How to suppress the generation of certain routes

I have this route in my routes.rb

resource: session

It generates the following routes

session_path    POST    /session(.:format)  sessions#create
new_session_path    GET     /session/new(.:format)  sessions#new
edit_session_path   GET     /session/edit(.:format)     sessions#edit 

I do not require edit_session_path (at least I don't know yet whether I require it or not) and I have a custom route for signin, so I don't want new_session_path.

Is there a way to tell Rails to not generate these two paths?

Upvotes: 0

Views: 72

Answers (3)

Marcus
Marcus

Reputation: 12586

Alternatively, if you know which actions you want you can provide it directly via only, instead of excepting them:

resources :sessions, only: [:create]

Upvotes: 2

zmii
zmii

Reputation: 4277

If you need more than 1 resource to configure

with_options(except: [:new, :edit]) do |opt|
  opt.resource :session
  opt.resource :another_resource
  opt.resources :people
end

like in this post

or like this - similar to the upper answer.

Upvotes: 1

jpriebe
jpriebe

Reputation: 824

resources :sessions, :except => [:new, :edit]

Upvotes: 2

Related Questions