SessionsController refactoring

A few weeks ago I worked on code like this: class SessionsController < ApplicationController respond_to :json, only: [:create] def create @user = User.find_by(email: user_params[:email]) if @user && @user.authenticate(user_params[:password]) @user.token = Session.create(user: @user).token end respond_to { |format| format.json { render_user } } end private def user_params params.require(:user).permit(:email, :password) end def render_user if @user render json: @user, status: :created else render json: { errors: 'Email or password was invalid' }, status: :unprocessable_entity end end end When you look on this code at first time, you probably think that this is not too bad. Class isn’t to long. It have about 25 lines....

Custom Rails Validators

For a few days I worked on custom validators in Rails. First what are validators? When you want to check some data which comes to your application, you use validators. For example: if email has specific format, if number is odd, or if you simply want to check if name is required for all of this we use validators. Rails has many different validators already in side. Check the documentation. But sometimes you want to do more. In my case I need validator for black list of words for string field. I know I can use build-in validator. But I...

RVM – Ruby Version Manager

I hit on an idea how to show: What exactly is RVM? RVM is like house with flowers. Each flower need special living conditions. One of them likes water, other doesn’t like strong light. If we want to flowers grown, we need to take care about this specific living conditions. In this cases help us RVM. Each project wrote in Ruby on Rails needs special environment. RVM help as to keep environments separate without problems.

MVC – design pattern

One of my target is writing about Ruby on Rails. So today we start. This article will be about main software design pattern in Rails. We call it MVC – Model View Controller. But from the beginning. What is software design pattern? Hmm… it is like good recipe for chocolate cake. Many people do chocolate cake onces better, others worse. But when we have good recipe we share it with others. They try and tell what they think about it. If it really good many people started using. The same is with software design pattern. It is some of good...

Rails Girls Silesia 2014

It took me a long way from being a participant in Rails Girls workshops, through being a mentor and right now organizing Rails Girls in Gliwice. I’m very proud of our team. It was hard work and lot of engagement. And now my dream came true! Let’s start this story from the beginning… My adventure with Rails Girls started in 2013. I got information about the Rails Girls workshop in Wroclaw. Unfortunately, because I was scared and not sure of my skills, I didn’t register. After registration was closed I regretted my decision. I promised myself that I will participate...

Guake terminal

Today, I would love to share with you a very simple, but useful tool. I use it for years now, and I think it is irreplaceable. This is Guake terminal. What is Guake? It is a drop-down terminal for Linux with GNOME Desktop Environment. When you use KDE Desktop Environment, you can check the Yakuake terminal. It’s similar to Guake. OK, but I don’t know which Desktop Environment I use? By default, GNOME is used by systems such as Fedora, Debian, Ubuntu, or Mint. So, if you use any of those Linux distributions, you probably use GNOME. Advantages of Guake...

Ruby Hash Tips

Today I will show you some Hash tips, which I like. But before that what really is this hash? Hash is a very specific Array where as a key we can use anything we want and order to this key some value or values. For example: If we have books and theirs authors. We can connect author to his books. When we call author then we see his/her books. hash = { 'Carlos Ruiz Zafon' => ['La Sombra del Viento', 'El Juego del Angel'], 'Antoine de Saint-Exupery' => 'Le Petit Prince' } hash['Carlos Ruiz Zafon'] # => ['La Sombra del...

Rails Girls Cracow

Rails Girls Cracow

This will be short note. A few weeks ago I was a coach on Rails Girls Kraków. This time workshops were differently. Girls were very young but with big motivation. I thought wonderful girls, with so much positive energy. They support me and I felt great teaching them. After all I have some new tips: