jendiamond / railsgirls-signup

https://railsgirls-signup.herokuapp.com
3 stars 3 forks source link

Add Devise for Authentication #29

Closed jendiamond closed 7 years ago

jendiamond commented 7 years ago

Pull Request #44

Pull Request #46

Don't Add Confirmable

Use Member not User

https://rubygems.org/gems/devise/versions/3.5.6
https://github.com/plataformatec/devise

User needs to be able to sign up so they can each upload their tutorials.


Add Devise gem to the Gemfile
gem 'devise', '~> 3.5', '>= 3.5.6'

Run the generator:
$ rails generate devise:install

In config/environments/development.rb add this:

   `config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }`

$ rails g devise:views


In the following command you will replace MODEL with the class name used for the application’s users (it’s frequently User but could also be Admin). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your config/routes.rb file to point to the Devise controller.

$ rails generate devise Member

Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.

$ rake db:migrate

Q. Are controllers in devise automatically generated? How do you access them?

A. http://stackoverflow.com/questions/6234045/how-do-you-access-devise-controllers

Devise uses internal controllers, which you can access and subclass in your own code. They are under the Devise module.

For example, to extend the RegistrationsController:

class MembershipsController < Devise::RegistrationsController
  # ...
end

Then all you have to do is configure Devise's routes to use your controller instead:

devise_for :members, :controllers => { :registrations => 'memberships' }


You should restart your application after changing Devise's configuration options. Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.


Continued instructions:
https://github.com/plataformatec/devise#controller-filters-and-helpers

jendiamond commented 7 years ago

After you bundle you'll see this...

Some setup you must do manually if you haven't yet:

  1. Ensure you have defined default url options in your environments files. Here is an example of default_url_options appropriate for a development environment in config/environments/development.rb:

    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

    In production, :host should be set to the actual host of your application.

  2. Ensure you have defined root_url to something in your config/routes.rb. For example:

    root to: "home#index"

  3. Ensure you have flash messages in app/views/layouts/application.html.erb. For example:

    <%= notice %>

    <%= alert %>

  4. You can copy Devise views (for customization) to your app by running:

    rails g devise:views