How to get the full path image url with carrierwave gem

In this post I’m going to cover how to get the full path url of an uploaded image using carrierwave gem.

By default carrierwave stores the uploaded images at /uploads/model_name/id/image.png

If you request the image url from the database it will only return the /uploads/model_name/id/image.jpg directory.

What if you need the full path ? Like:

The only thing you need to do is to to set the asset_host in your development/production environment:Captura de Tela 2016-06-05 às 07.56.20.png

After that you need to restart your server and now you can get the full path of the image.

Feel free to ask questions and make suggestions🙂

See you guys in the next time.

Shoucast Streaming in iOS (Objective-C)

In this post I’m going to cover how to build an iOS app that streams songs from Shoutcast server.

  1.  Open your XCode and Create a new project, select Single View Application and click in Next

Captura de Tela 2015-12-01 às 22.18.42

2. Name your app for Shoutcast, and then select Objective-C, and click in Next

Captura de Tela 2015-12-01 às 22.18.58

3. Create a button and name it play. This button will start the streaming

Captura de Tela 2015-12-01 às 22.26.59

4. Go to View->Assistent Editor->Show Assitent Editor

Captura de Tela 2015-12-01 às 22.27.39

5. Create an action called playMusic like the picture below:

Captura de Tela 2015-12-01 às 22.32.23

6. Open your ViewCotroller.h to create a property called myStreaming(you should create this property as strong, if you don’t do this the streaming will stop after 2 seconds)

Captura de Tela 2015-12-01 às 22.35.41

7. Now go to your ViewController.m and inside the method playMusic you should call the property you defined in your h file.

The First thing you need to have is the streaming URL (shoucast’s urls should have the address and the port), then your need to init the streaming property, after that you should define the source type, in our case is streaming, after all you just need to set shouldAutoPlay to NO and prepare to play the streaming and finally play.

– (IBAction)playMusic:(id)sender {    

 NSURL *myUrl = [NSURL  URLWithString:@”″];

 self.myStreaming = [[MPMoviePlayerController alloc] initWithContentURL:myUrl];

  self.myStreaming.movieSourceType =         MPMovieSourceTypeStreaming;

   self.myStreaming.shouldAutoplay = NO;

   [self.myStreaming prepareToPlay];

   [self.myStreaming play];


After all, run your app and listen to the radio🙂

That’s all, thanks🙂.

If you have any questions, feel free to ask.

See you guys next time!

Cpf_Validation Gem

Some days ago I released my first gem for CPF validation.

I’ve seen many gems which do the same but the authors seem to no update them.

You can help me to improve this gem by sending a pull request on github:


As gem:

# in Gemfile
gem 'cpf_validation'

# Run bundler
$ bundle install


Validating a CPF attribute:

class Patient < ActiveRecord::Base
  validates_cpf :cpf_attr
  # or
  validates :cpf_attr, :cpf => true

Validating an attribute that can store CPF:

class Customer < ActiveRecord::Base
  validates_cpf :cpf_attr
  # or
  validates :cpf_attr, :cpf => true

Regular validation options:

:allow_nil   - Allows a nil value to be valid
:allow_blank - Allows a nil or empty string value to be valid
:if          - Executes validation when :if evaluates true
:unless      - Executes validation when :unless evaluates false
:on          - Specifies validation context (e.g :save, :create or :update). Default is :save

Working with Sinatra – Part 2

In the last post I showed how to install Sinatra and how to write a simple code. In these post I’m going to cover Views. View is the V of MVC pattern.

First of all you need to create a folder called views

mkdir views

In this folder you’ll put all your views files .erb or .haml.

To render a view you need to define the format of the view (.erb or .haml) and the name of your view.


get '/' do
  erd :index

This code will render a view called index in the views folder.

Obs: You need to create a view called index.rb in your views folder.

You can also define a template in your views folder and use it in some of your views


get '/' do
  erb :index , layout: :post

This code will render the view index with the post layout (views/post.rb)

There are  many availble options in the options hash.

Here all of them:

List of locals passed to the document. Handy with partials. Example: erb "<%= foo %>", :locals => {:foo => "bar"}

encoding to use if uncertain. Defaults to settings.default_encoding.

Views folder to load templates from. Defaults to settings.views.

Whether to use a layout 
(true or f   alse). If it's a Symbol, specifies what template to use. Example: erb :index, :layout => !request.xhr?

Content-Type the template produces. Default depends on template language.

Scope to render template under. Defaults to the application instance. If you change this, instance variables and helper methods will not be available.

Template engine to use for rendering the layout. Useful for languages that do not support layouts otherwise. Defaults to the engine used for the template. Example: set :rdoc, :layout_engine => :erb

Special options only used for rendering the layout. Example: set :rdoc, :layout_options => { :views => 'views/layouts' }

In the third part of this post we will start coding a simple blog application.

See ya!

Working with Sinatra – Part 1

Sinatra is a DSL for creating quickly web applications in Ruby.

It’s true you can build many web applications with Ruby on Rails, but sometimes you don’t need too much, there are situations you need a simple application and RoR seems to be too much to solve it.

Install the gem

gem install sinatra

Create a ruby file

# mywebapp.rb
require 'sinatra'

get '/' do
  'Hello Sinatra'

Run it

ruby mywebapp.rb

Sinatra runs on http://localhost:4567 as default.

Captura de Tela 2015-04-25 às 09.01.35

This defines a simple HTTP method paired with a URL matching pattern. In this case, in the root page it will show a greeting.

get '/' do
  'Hello, Sinatra'

In part two of this post we will work with Views/Templates.