サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
アメリカ大統領選
nithinbekal.com
Tail call optimization is an optimization where tail recursive functions are transformed into loops by the compiler. A tail recursive function is one where the final statement is a call to the same method. In this post, we will look at what tail recursive functions look like, how tail call optimization helps them, and how to enable TCO in Ruby. Recursion The factorial function provides an excellen
Modeling recurring events in a calendar is an interesting problem to solve. There are many different scenarios in which you might need to model recurring events, but in this article I will walk through a simple example of weekly recurring events in a Rails app. Although this post covers most of the code needed for the example, I will skip over some of the details (such as views), and you will have
When your models are bloated with methods that are only used in views, it might be a good time to refactor them. Moving that logic into helper modules might be OK in some cases, but as the complexity of your views grows, you might want to look at presenters. Presenters give you an object oriented way to approach view helpers. In this post, I will walk through how we refactored our views to use pre
Rails 5.0 is almost here! The first beta version has been released already, and you can try out some of the shiny new features right away. So what are the new features? Let’s take a quick tour of the new features and major changes. ActionCable Websocket support in Rails is the most talked about feature in Rails 5. This will make it super easy to add realtime features to your app. If you’re plannin
Ruby 2.3.0 will be released this Christmas, and the first preview release was made available a few weeks ago. I’ve been playing around with it and looking at what new features have been introduced. # Install using RVM rvm install 2.3.0 # Using Rbenv brew upgrade ruby-build --HEAD rbenv install 2.3.0 Safe navigation operator A new operator (&.) has been introduced. It can be very useful in cases wh
Building a chat application using Elixir and Phoenix 11 Jul 2015 I’ve been looking at Phoenix channels lately, and going through Chris McCord’s Phoenix chat example gives a great intro to getting started with it. In this post, we’ll be walking through the process of building the same app step by step. We’ll use Elixir 1.0.5 and Phoenix 1.0.0. (This was originally written for Phenix 0.14, but was l
Getting started with Rails 5's ActionCable and websockets 17 Jul 2015 ActionCable is the websockets framework that ships with Rails 5. It aims to simplify the addition of realtime features to Rails apps. In this tutorial, we will explore ActionCable by building a simple chat application. Let’s get started by installing the pre-release version of Rails (5.0.0.beta). Once the final 5.0.0 version of
User authentication from scratch in Elixir and Phoenix 30 Jun 2015 In my previous post about Phoenix, we built a very simple blog app. We only added the ability to post content, but there’s no user authentication system. In this post, we will add user authentication to the app. There are excellent authentication libraries out there like passport and addict, but here we’ll be writing authentication
Getting started with Phoenix: Building a scaffolded CRUD app 30 May 2015 Lately I’ve been looking at the Phoenix web framework for the Elixir language. Phoenix has taken a lot of inspiration from Rails, and the structure of a project feels somewhat familiar if you’ve worked with Rails. To get familiar with the framework, I’m starting with a simple CRUD app using Phoenix’s scaffolding generator. Th
If you’re reading this, you’re probably contemplating a long painful process of getting your Rails app to a newer version. I recently updated a Rails app from 3.2 to 4.2, and this guide contains the general guidelines to follow for making the upgrade easier. If your Rails app is on version 4.0.x or below 3.2, it’s very important that you upgrade immediately, since they no longer receives security
When passing locals to Rails partials, you might run into cases where you need to pass optional locals in some places, but don’t want to pass it in every other place where you use the partial. As an example, you have a _post partial which you render like this: <%= render 'post', post: post %> And now you want to render the same partial from another view, but this time you want to pass a boolean fl
The flip flop operator is one of those weird features of Ruby that most people aren’t even aware of. It’s one of the many Perlisms that sneaked into Ruby, but hasn’t caught on. In this post, we will look at what flip-flop operators are, and where you can use them. What is it? The flip flop operator is a range (..) operator used between two conditions in a conditional statement. It looks like this:
Decorators allow us to add behavior to objects without affecting other objects of the same class. The decorator pattern is a useful alternative to creating sub-classes. We will look at an example where we use subclassing to solve a problem, and then look at how decorator objects provide a better solution. Imagine we have a Burger class with a cost method that returns 50. class Burger def cost 50 e
Exporting data to CSV from a Rails app is as simple as adding a respond_to block to the controller action and setting the proper response headers. As an example, let’s consider a users#index action which lists the users for admin. Now if you want to allow the admin to download the list as CSV, this is how it can be done: Require Ruby’s built in CSV library in ApplicationController. require 'csv' I
This article is about building a gem from scratch. The recommended way to create a gem today is to use bundler’s bundle new <gemname> command. This article is meant to take a closer look at what is generated by such tools by building it by hand. Writing a Ruby gem is a lot easier than it sounds. Many tutorials about writing gems recommend using something like (Jeweler or Hoe) bundler to create the
このページを最初にブックマークしてみませんか?
『Nithin Bekal』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く