Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Generating sessions views in Ruby on Rails?

I ran the command rails generate controller sessions to build my sessions applications file. The sessions_controller.rb and /views/sessions/ folder were created. However, I am not seeing the following files in the sessions folder:

create.html.erb
destroy.html.erb
new.html.erb

Are these files supposed to be auto generated or is it okay to create them manually?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

rails g controller sessions

will only create a controller itself and a directory to house the views, no routes or view files.

To get those files, instead run

rails g controller sessions create destroy new

Note that when the routes are generated for this, they will not be named routes. They will loo like:

  get 'sessions/create'
  get 'sessions/destroy'
  get 'sessions/new'

So it might be preferable to change those to a resource

resources :sessions, only: [:create, :new, :destroy] 

which will give you the ability to use those paths, eg,

new_session_path

Alternatively, you could create you own names for them

  get 'sessions/new', to: 'sessions#create', as: :new
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading