Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the best way to create a login in Rails for a starter?

I've seen there're several engines and tutorials about it, but I couldn't figure out which one could help me out in short terms. I'm just learning Rails and Ruby and my aim is to understand how it works while it can be useful in a real life event.

Any link or explanation about this will be kindly appreciated!

like image 278
Zentaurus Avatar asked Aug 17 '13 19:08

Zentaurus


People also ask

Why should I use Ruby on Rails?

RoR For Agile Project Development The web application development on Ruby on Rails allows taking required changes quickly without affecting the code and application quality. Usage of Ruby on Rails helps developers debug the code simultaneously while writing.

How do I create a controller in Rails?

To generate a controller and optionally its actions, do the following: Press Ctrl twice and start typing rails g controller. Select rails g controller and press Enter . In the invoked Add New Controller dialog, specify the controller name.

How do I start a Rails server?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option.


2 Answers

a gem called devise, as simple as install it and minimal configuration

https://github.com/plataformatec/devise

add it to gem file:

gemfile.rb

gem 'devise'

install :

rails generate devise:install

create User model:

rails generate devise user

and here are the commands you can use:

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

like image 170
Rodrigo Zurek Avatar answered Oct 12 '22 22:10

Rodrigo Zurek


Other answers are recommending Devise. Devise's own documentation says:

If you are building your first Rails application, we recommend you to not use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch.

I'm inclined to agree. Devise is a great engine that can create a powerful login system for you in minimal time, but if you're building an app for the purpose of learning Rails, I'd recommend following a tutorial to build your own login system so you get a deeper understanding of what's actually going on beneath the hood. You can always come back and use Devise later.

For a tutorial, I'd recommend the same book that Devise recommend, Michael Hartl's Ruby on Rails Tutorial - specifically chapters 6, 7, 8. (Well, I'd recommend the whole book, but those are the chapters that pertain to building a login system.)

If screencasts are more your thing, Ryan Bates's Railscast on the subject is supposed to be good although I haven't watched it myself.

like image 25
GMA Avatar answered Oct 12 '22 22:10

GMA