Basics of Sessions, Cookies and SEO in Rails

Rails uses a CookieStore to handle sessions. What it means is that every one of the information expected to recognize a client’s session is sent to the customer and nothing is put away on the server. When a user sends a request, the session’s cookie is processed and validated so rails, warden, devise, etc. can figure out who you are and instantiate the correct user from the database. Sessions: A session is just a place to store data during one request that you can read during later requests. Session is the perfect place to put data – specifically, the parts of the data you want to keep around for more than one request. Most apps need to be able to store some data about a user. Usage of Sessions: example:
session[:current_user_id] = @user.id
Cookies: Cookies are key-value data pairs that are stored in the user’s browser until they reach their specified expiration date. Cookies are stored on the user’s computer. The information is later sent back from the browser to the server. The user can manually delete cookie by restarting the browser or restarting the whole system. Here’s how we can call the methods: Example:
    def set_cookies
                       cookies[:customer_number] = "1234567890"
                   end
                   def show_cookies
                         @customer_number = cookies[:customer_number]
                    end
                    def delete_cookies
                          cookies.delete :customer_number
                    end
SEO: Search engine optimization Site improvement (SEO) is the way toward influencing the perceivability of a site or a website page. We can use the meta-tags gem to make our rails application SEO friendly. Meta Tags are utilized to outline data of a page, But the data is not directly visible to us viewing any page. Meta Tags are the primary tool for SEO, meta-keywords and meta-description very popular now-a-days. Importance of meta-data is increasing day by day. Meta-description means have to write about our page, so that search engines will come to know what themes and topics our website is relevant to. Search engines use meta-description display all summary on search result page. So if our meta descriptions are well written we might be able to attract more our website. For example:
Configuration and setup in rails: First we have to install the gem:
gem  'meta-tags'
bundle install In config/initializers we have to create one new file meta_tags.rb and in that we have to mention the following:
MetaTags.configure do |c|
  c.title_limit        = 70
  c.description_limit  = 160
  c.keywords_limit     = 255
  c.keywords_separator = ', '
 end 
SEO basics and metatags: Titles: Page titles are essential for Search engines. The titles in the program are shown in the title bar. For example:
set_meta_tags title: 'Divyas_Page'
Description: Description tags are called meta tags as they are not showed by the programs as that of titles. Be that as it may, these portrayals might be shown by some web indexes. They are utilized to portray the substance of a page in 2 or 3 sentences. Example:
set_meta_tags description: "Description needs to come here"
Keywords: Meta keywords tag are utilized to put your keywords that you think a surfer would seek in Search engines. Rehashing keywords pointlessly would be considered spam. Example:
set_meta_tags keywords: %w[keyword1 Keyword2 KeyWord3]
Noindex: By utilizing the noindex meta tag, you can flag to web crawlers to exclude particular pages in their files. Example:
set_meta_tags noindex: true
Nofollow: Nofollow meta tag advises a web search tool not to take after the connections on a particular page. It’s totally likely that a robot may locate the same connections on some other page without a nofollow (maybe on some other site), so it still touches base at our undesired page. For example:
 set_meta_tags nofollow: true 
Follow: Follow will work with Noindex meta tag Example:
 set_meta_tags noindex: true, follow:true
This is how sessions, browser cookies and SEO work for a rails application and how authentication is built for these applications.

Subscribe For Latest Updates

Related Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish