Skip to main content

Ruby on Rails application using Devise

Devise is a flexible authentication solution for Rails. It is a complete MVC solution based on Rails engines. It allows you to have multiple models signed in at the same time. It hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
STEP 1. gem ‘devise’ install.
STEP 2. run bundle install
STEP 3. run rails generate devise:install
STEP 4. run rails generate devise:views
STEP 5. Here in this application we mainly need 2 models, one is member model and the other one is contact model. So now we are going to create our member model using devise:run rails generate devise member The migration file will located in db/migrate/ devise_create_members.rb.

STEP 6. After that you should have to run rake db:create (For creating new database)
STEP 7. run rake db:migrate
Once you run the db:migrate command, rails will create a table called members with the following field that the Devise specified in the migration file. Check the tables have created successfully.
STEP 8. run the server by typing “rails server” and copy and paste the 1 and 2 address to your browser search bar.
  1. http://0.0.0.0:3000/members/sign_up
  2. http://0.0.0.0:3000/members/sign_in
STEP 9. run rails generate migration add_username_to_members username:string
we have to add the username to the sign-up form. This command will generate another migration file in your “db/migrate” directory.

STEP 10. run rake db:migrate
STEP 11. run rails generate model contact
Edit the migration file of contact and specify the 2 fields as shown below. Open db/migrate/ 20180312073055_create_contacts.rb

STEP 12. run  rake db:migrate
STEP 13. run  rails generate controller home
And then create a new index file for home controller like “app/views/home/index.html.erb” and then add the following

STEP 14. Once you have done, Open app/config/routes.rb
add the line
root :to =>’home#index’
STEP 15. run rails generate controller registration
Open “app/controllers/registration_controller.rb” and then edit the file as shown below

STEP 16. We have to mention the relationships between 2 models (member,contact). Here the relationship will be as follows.
Open_Filepath : app/models/member.rb

Open_Filepath : app/models/contact.rb

STEP 17. Now refer the registration controller file in app/controllers/registration, here after completing the registration & the values that the member entered is stored in the table successfully, I just redirected the member to the dashboard page. So we have to add that page to our home controller.
Open_Filepath : app/views/home/dashboard.html.erb

STEP 18. Open app/config/routes.rb and you have to specify this path in our routes.rb file

STEP 19. run “rails s” and go to http://localhost:3000 address to your browser search bar

Source:  http://www.cryptextechnologies.com/blogs/ruby-on-rails-application-using-devise

Comments

Popular posts from this blog

GraphQL With Ruby

Now a day’s most of the web or mobile applications fetch data from server which is stored in a database. REST API provides an interface to stored data that require by the applications. GraphQL is a query language for REST API's not for server databases. It is database agnostic and effectively can be used in any context where an API is used. GraphQL provide platform for declarative data fetching where client need to specify what data needs from API in response. Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data a client asked for. GraphQL minimizes the amount of data that needs to be transferred over the network and improves applications operating under these conditions. Introduction to GraphQL API on Ruby on Rails Start with adding gem in Gemfile gem ‘graphql’ Run command bundle install Run command rails generate graphql:install Above command will add gr

Best In Place Gem In Ruby On Rails Tutorial

The best_in_place gem is the easiest solution for in place editing in Ruby on Rails. This gem provides functionality of “in place editing” in ruby on rails without writing any extra ajax code. It supports text inputs, textarea, select dropdown, checkboxes, jQuery UI Datepickers, etc. Also Displays server-side validation Installation Steps of “best_in_place” Gem : Installing best_in_place is very easy and straight-forward. Just begin including the gem in your Gemfile: gem ‘best_in_place’ After that, specify the use of the jquery and best in place javascripts in your application.js, and optionally specify jquery-ui if you want to use jQuery UI datepickers: //= require jquery //= require best_in_place //= require jquery-ui //= require best_in_place.jquery-ui Then, just add a binding to prepare all best in place fields when the document is ready: $(document).ready(function() { /* Activating Best In Place */ jQuery(".best_in_place").best_in_place(); });

Data scraping in Ruby on Rails using Nokogiri and Mechanize Gem

What is Data scraping? Website/Data  Scraping  is a technique to operating large amounts of  data  from websites whereby the  data  is extracted and displayed in own sites or it can be stored to a File/Database. Data scraping is basically used where the websites does not provides API. Some Applications do not provide API to collect records. For the same , Data Scraping technique is used. The data can be scraped using Nokogiri Gem. The steps are required: Add the gem “gem ‘nokogiri’, ‘~> 1.8’, ‘>= 1.8.1'” . Then run the bundle install Add the “require ‘nokogiri'” , “require ‘open-uri'” line where you will write the code for the scraping. The controller of the page will look like below: The view of the code of view page will look like : The result in our application will look like: Mechanize Gem in rails The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follo