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

This is first episode about programs which I use. I think, finally it will be few this kind entries. To day I would like to start talking about Guake. But first what is Guake? It is drop-down terminal for Linux with GNOME Desktop Environment. When you use KDE Desktop Environment, you can have Yakuake terminal. It is similar to Guake. OK but I don’t know which Linux use GNOME? By default GNOME use system such as Fedora, Debian, Ubuntu or Mint. Guake is simple tool. After download and install Guake, you can start this tool. Then whenever you press F12...…