<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: bbborisk</title>
    <description>The latest articles on DEV Community by bbborisk (@bbborisk).</description>
    <link>https://dev.to/bbborisk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F208412%2Fe9313c11-9305-49f1-acc9-386e18fe2e9c.jpeg</url>
      <title>DEV Community: bbborisk</title>
      <link>https://dev.to/bbborisk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bbborisk"/>
    <language>en</language>
    <item>
      <title>Simple authentication and styling in beginner Rails 6 project</title>
      <dc:creator>bbborisk</dc:creator>
      <pubDate>Fri, 24 Jan 2020 13:47:42 +0000</pubDate>
      <link>https://dev.to/bbborisk/simple-authetication-and-styling-in-beginner-rails-6-project-m6</link>
      <guid>https://dev.to/bbborisk/simple-authetication-and-styling-in-beginner-rails-6-project-m6</guid>
      <description>&lt;p&gt;Ok so, here goes my first tech blog post. I've been trying to do this for a while, but just didn't have the courage to get my self to do it. So, this is a bit about &lt;em&gt;how to do this thing&lt;/em&gt; and a bit about &lt;em&gt;how to overcome imposter syndrome&lt;/em&gt; for absolute beginners.&lt;/p&gt;

&lt;p&gt;Let's just dive in. I have started a project driven by my wife's and my need to systematize hundreds of children's books we have for our toddlers. And I know, we could've made this in a few excel sheets, but my goal here is to make something of my own, customizable and editable.&lt;/p&gt;

&lt;p&gt;And I love rails, for it is so beginner-friendly, yet so powerful.  First, &lt;br&gt;
I generated the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails new ChildrensBooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rails 6 takes a bit longer to generate, but it has tons of features, which I am still learning about. After making the index page, the next thing is to add gems for authentication and bootstrap templates. so, in gemfile, add gems &lt;code&gt;devise&lt;/code&gt;, &lt;code&gt;devise-bootstrap-views&lt;/code&gt; and &lt;code&gt;twitter-bootstrap-rails&lt;/code&gt;, which is simple and easy to use. You also need &lt;code&gt;jquery-rails&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'jquery-rails'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'devise'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'twitter-bootstrap-rails'&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'devise-bootstrap-views'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, of course, install them with bundler - &lt;code&gt;bundle install&lt;/code&gt;. Now, there are better ways to do this, but again, I'm doing this in the simplest way possible. Then, onto making model for the Users table. &lt;/p&gt;

&lt;p&gt;In order to use &lt;code&gt;devise&lt;/code&gt;, you must first install it with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails generate devise:install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, generate Users model. Devise makes it so simple, also making all the routes in &lt;code&gt;routes.rb&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails generate devise User
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a perfect setup for me at this moment, no need for other configurations. so I just migrated the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The styling idea I got from some Udemy course I saw a while back, and it seems great now. It adds a twitter style outlook, and is both available for page layout and devise form aswell. &lt;br&gt;
First, add the bootstrap requirements to the style resources file.&lt;br&gt;
application.css:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="nt"&gt;require&lt;/span&gt; &lt;span class="nt"&gt;twitter-bootstrap-static&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nt"&gt;bootstrap&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and application.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//= require twitter/bootstrap&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, include both files in manifest.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//= link_tree ../images&lt;/span&gt;
&lt;span class="c1"&gt;//= link_directory ../stylesheets .css&lt;/span&gt;
&lt;span class="c1"&gt;//= link application.js&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, install the theme. I used static, but in the documentation of the gem you can find others as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails generate bootstrap:install static
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then, it is just the matter of adding &lt;code&gt;views&lt;/code&gt; and updating the &lt;code&gt;application.html.erb&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails g bootstrap:layout application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then same for devise&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails g devise:views:locale en
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rails g devise:views:bootsrap_templates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That should do it. &lt;/p&gt;

&lt;p&gt;In my &lt;code&gt;application_controller.rb&lt;/code&gt; I added the before_action for authentication&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;before_action&lt;/span&gt; &lt;span class="ss"&gt;:authenticate_user!&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so, when I run the server, it takes me straight to the login screen. From there, you can make a user and, I guess, that is it.  &lt;/p&gt;

&lt;p&gt;So, the next thing for me is making a model for books. I know this isn't the most brilliant text or groundbreaking tutorial. It is basically my experience in making the starter code following the documentation in gems. But I hope it helps someone, and it really helped me break the ice in the community.&lt;/p&gt;

&lt;p&gt;Feel free to get in touch, share your journey into coding world, share knowledge and tips for this newbie. &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>bootstrap</category>
      <category>beginners</category>
      <category>books</category>
    </item>
  </channel>
</rss>
