Google Maps in Ruby on Rails

It is little tutorial how to setup gmaps4rails gem. I have problem with latest version thats why i show it with 1.5.6 version.

We will start with creating new project. Go to the directory of your choice and in your terminal type:

rails new projectname
cd projectname

 

2) Edit gemfile by adding new line:

gem ‘gmaps4rails’, ’1.5.6′

and bundle it by typing in your terminal:

bundle install

 

3) Add gmaps4rails assets to the application:

rails generate gmaps4rails:install

4) Generating simple scaffold will serve enough for our purposes:

Read more >>
Posted in Ruby on Rails

CKeditor under Ruby on Rails

CKeditor

CKEditor is a ready-for-use HTML text editor designed to simplify web content creation. It’s a WYSIWYG editor that brings common word processor features directly to your web pages. Enhance your website experience with our community maintained editor.CKeditor és a

Ruby on Rails

 

You can easily implement ckeditor into your ruby on rails project.

 CKeditor gem download page with full documentation:  https://rubygems.org/gems/ckeditor

Install

You can insert this code to your gemfile.

Read more >>
Posted in Ruby on Rails

PDF generation Ruby on Rails

PDF generating

 

Sometimes we come to a situation while building a website, when we would like to save data to a file. Rails provides several opportunities. We can create and format the content using ruby with a DSL (domain-specific language) or convert our HTML code to PDF using a library.

 

There are two programs to implement these methods, Prawn and PDFKit. I want to present the working of Prawn.

 

Prawn:

First we have to add the gem to the Gem file to use Prawn:

gem ’prawn’

bundle install

Read more >>
Posted in Ruby on Rails

Negative Captcha – Ruby on Rails

The main purpose of captcha is to filter out the uninvited messaged(SPAM) sent by bots, so we can differentiate computers and human users. We use negative captcha with registration and comments, as below: 

Since 2007 negative captcha has become popular worldwide, because it doesn’t disturb users by asking for proof if they are human, rather try to get the spammer’s program to reveal itself. The usage of negative captcha is really easy, you just have to create some new input fields and hide it from the user so they cannot fill them, because they are invisible. However, most bots fill out every fields. Then we only have to check if are there any filled invisible fields. If there are any, we should think, that they are filled out by a bot, so we can just abort the procession. 

Read more >>
Posted in Ruby on Rails

Fájlmegosztó oldal készítése

A tutorial leírása:

A tutorial segítségével egy a toldacuccot.hu -hoz hasonló fájlmegosztó alkalmazást készítünk. A két fő funkciója maga a fájlfeltöltés, valamint erről az értesítő e-mail küldése egy a felhasználó által megadható címre.

Követelmény:

- Telepített ruby on rails (a tutorial 4.1.8 -on készült)

A tutorial:

Először is szükségünk van 1 modell -re, valamint hozzá tartozó controllerre. Ezek elkészítésének részleteibe nem mennék bele, leírás róla itt.

Én model névnek data_file -t választottam, így létrejött egy data_file.rb fájl a modelsben a controller generálása után pedig egy data_files_controller.rb a controllers mappában. Valamint a views mappában egy data_file nevű mappa.

Read more >>
Posted in Ruby on Rails

Rails with Bootstrap and form validation

Requirements

  • Ruby installed
  • Rails up and running
  • SQLite3 installed
  • Rails basics
  • HTML basics
  • CSS basics

What is Bootstrap?

Bootstrap is a framework that makes it easy for web developers to create nice looking and responsive websites or web applications. There are predefined css classes for creating common components such as tables, forms, widgets, navigationbars, and more. The framework also provides Javascript to create things like modals, popovers, scrollspies, and more. Their documentation is very through, providing example code for most, if not all of the components that Bootstrap provides.

Create a Rails application

First we need a Rails application. Let’s create a simple todo application.

Read more >>
Posted in Ruby on Rails

Select2 integration into Ruby on Rails

In this article I’ll demonstrate a simple usage of Select2 in a Ruby on Rails environment.

About Select2

Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

Setting up

First we need a project, so let’s create one:

rails new Select2Rails

To include Select2 we have to add the select2-rails gem to our Gemfile and then run bundle install:

gem "select2-rails"

Next we have to include the javascript and stylesheet assets. To app/assets/javascript/application.js we add:

Read more >>
Posted in Ruby on Rails

Infinite scroll implementation with Ruby on Rails

In the following article, I will going to show you how to implement a basic infinite scroll with the use of Ruby on Rails.

Requirements:

  • Sprockets

  • haml

  • coffee

Implementation:

1)

First you will have to download the infinite_scroll implementation from github:

https://github.com/levymetal/infinite-scroll

This project was made by Cristian Varga and it is one of the most simple solutions that you can find on the internet.

This solution is using the will_paginate gem and the jquery.inview plugin that you can find on https://github.com/protonet/jquery.inview

Read more >>
Posted in Ruby on Rails

Ruby on Rails: DataTables integration and sorting plugin creation

Introduction

DataTables is a very handy extension of the jQuery library which extends the basic HTML table with new functionality and design. In this article I would like to show you how to integrate DataTables in a Rails application and how to create a plugin for sorting columns.

Integrating DataTables in a Rails application

For using DataTables in a Rails application first we need to specify the DataTables gem in our Gemfile.

gem jquery-datatables-rails, github: rweng/jquery-datatables-rails

Then we need to install the gem.

bundle install

After adding the gem to our application we need to specify the external javascript and css files for DataTables in asset files.

Read more >>
Tagged with: , ,
Posted in Ruby on Rails

How to connect Rails with MongoDB with example project

Rails + MongoDB tutorial, demonstrated through a Todo app

For these tutorial I use the Ubuntu 12.04 OS.

1./ Install Ruby on Rails

For Rails development, it is a good practice to use a version manager, because there are major differences between the versions of both the Ruby language and the Rails framework. The most popular version manager is RVM.

System preparation.

First update the package manager.

   $sudo apt-get update

Install curl, wich is used to install RVM.

   $sudo apt-get install curl

Install RVM and Ruby.

Read more >>
Posted in Ruby on Rails

Ruby gem creation and publishing

ASSUMPTIONS

This tutorial assumes the following:

  • You have ruby installed
  • You have a github account
    • SSH pub key set up
    You have a rubygems.org account

    INTRODUCTION

    Creating and publishing your own gem is simple thanks to the tools baked right into RubyGems. Let’s make a simple “hello world” gem. The code for the gem we’re going to make is up on GitHub.

    Remember if you are doing this under Windows as I was doing it, use “Administrator: Start Command prompt with Ruby”.

    YOUR FIRST GEM

    I started with just one Ruby file for my hello gem, and the gemspec. You’ll need a new name for yours (maybehello_yourusername in my case hello_tvsze) to publish it. Check the Patterns guide for basic recommendations to follow when naming a gem.

    Read more >>
Tagged with: ,
Posted in Ruby on Rails

DS18B20 temperature sensor’s connecting and programming Raspberry Pi

What hardware do I need?

  • Raspberry Pi – mini Pc
  • DS18B20 – Temperaturesensor
  • 4.7 K Ω-os resistor
  • Breadboard
  • Wires

rsz_imag0378

Assembly: 

The sensors should be connected to GPIO Pi pins as follows:

  • 3.3V - pin 1 (3.3V)
  • GND - pin 6 (Ground)
  • data – pin 7 (GPIO 4)
  • Finally, the 7.4 K Ω resistor should be placed in the data and 3.3V foot.

ds18b2002

rsz_imag0375 

rsz_imag0374

Software:

  • The Pi-installed on a Linux-based OS Rasbian, that can be downloaded from here.
  • Python script to read out.

Reading data:

Before any data is read out from the sensor software modules should be set. Then you’ll read in the measured values​​. 
Open a terminal in the Pi. Then run the following commands.

sudo modprobe w1-gpio
sudo modprobe w1-therm
cat /sys/bus/w1/devices/28-*/w1_slave

You will see someting like this:

Temp_console

After setting up the software modules display out the obtained sensor data. Two lines can be seen. At the end of the first line YES or NO will be used to indicate to us the correct reading of the measured value. If NO text obtained by repeating the last command we probably eliminate the error. The first line shows a more automatic CRC checking. 
At the end of the second line there is the temperature value in degrees Celsius three decimal places accuracy (the decimal point does not make it out).

Read more >>
Posted in Uncategorized

Symfony2 using forms with ajax

Basically we want to eliminate the page reload between form sends. If we want to eliminate this we need to use ajax for it. Usually a form have multiple fields that can or can’t be seen by the user, and there are two main property that we need. The first one is the form action that contains the url, and the second one is the method. We can easily get all the information like this:

var url = location.protocol +’//’ + location.host + $(’$idOfTheForm’).attr(’action’);

var method = $(’#idOfTheForm’).attr(’method’);

var formValues = {};

$.each($(’#idOfTheForm’).serializeArray(), function(i, field){

       formValues[field.name] = field.value;

}

As you can see we save the method, the action ,and all the form fields with values. After we get all the important information we just simply pass these data to our ajax call. Now comes the other part, we need to take care of it in our controller. We don’t need to modify all the action, we just need to change the return values. We going to need all the form errors, and a simple success value. Usually we dont need to take care of the form errors because it’s automatically handled, but now we need. To achieve this we need to loop trough all the form error-s and put them in an array. If you need to translate these messages you can just easily add a translator to it.

Read more >>
Posted in Javascript, Symfony

Using the Google Chart API

Maybe one of the most easiest to use diagram visualizer tool is the Google Chart tool. You only need to know JavaScript to work with.

1. Initialization

The Google Chart tool needs three necessary JavaScript library to work:

  • Google JSAPI – AJAX based library loading tool
  • Google Visualization – JavaScript based visualization tool for datasets
  • Chart library

First of all, we need to insert the JSAPI library into the <head> section of our page.

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

After that, we have to decide on which chart type we want to use, and we have to include the corresponding Visualization API:

Read more >>
Tagged with: , , , ,
Posted in Javascript

Ruby on Rails: Search & autocomplete with Sunspot, Solr and Twitter Typeahead.js (Part #2)

In the first part we created our simple models in Rails and added search information with the help of Sunspot. In this part we will create a search box with an autocomplete by using typeahead.js.

We will use the twitter-typeahead-rails gem to include the necessary javascript files into our Rails project, so we have to add it to our Gemfile:

gem 'twitter-typeahead-rails'

We also have to include the necessary files in our application.js. So, add the following to app/assets/javascripts/application.js:

Read more >>
Tagged with: , , , ,
Posted in Javascript, Ruby on Rails

Ruby on Rails: Inheritance in translation with fallback chain

If Rails can’t find the translation, the default I18n module just returns a “translation missing” error message or raises an exception if you tell it so.

In I18n module you can replace the default backend (Simple backend):

Create a new file: config/initializers/i18n_backend.rb

require "i18n/backend/fallbacks"
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

With this backend you can set a fallback chain (in the same file):

I18n.fallbacks.map(:de => :en)
I18n.fallbacks.map(:en => :hu)

In that case if Rails can’t find the German translation, it will attempt to find the English translation, and if can’t find it, it will attempt to find the Hungarian translation.

Read more >>
Tagged with: , ,
Posted in Ruby on Rails

Ruby on Rails: Active Admin, Ransack and Globalize, Part 1

Active Admin is a framework-within-framework for Ruby on Rails, aiming to provide a customizable administration interface. It provides various features useful in creating and managing multiple types of models in your application. Two of these come in handy when we’re only interested in a subset of all records:

Filters are no doubt familiar. They narrow down display to items whose attributes match user-provided values.

Scopes are a feature of ActiveRecord that allow us to predefine criteria for displaying items, that can later be referred to by name. Active Admin integrates this feature in its interface and lets us apply scopes by clicking a button on a particular model’s index page.

Read more >>
Posted in Uncategorized

Ruby on Rails: many-to-many relationship with ActiveAdmin

Many-to-many relationships are well documented on  RubyonRails guides. Though using it in ActiveAdmin is a bit more difficult. This is a step-by-step description how to implement ActiveAdmin forms using many-to-many relationships.

In our example we have a Car model. Every car has several Parts. Certainly one part can belong to more cars. (In truth when I say car, I think of CarBrand, like Audi A4, and when I say Part, I think of PartType, like wheel, tyre, clime, etc.) We want to set up several parts for a car entity through the car’s ActiveAdmin form.

Read more >>
Tagged with: ,
Posted in Ruby on Rails

Ruby on Rails: Search & autocomplete with Sunspot, Solr and Twitter Typeahead.js (Part #1)

Most websites provide search functionality. You can improve the usablity of your search if it has an autocomplete feature. In this post we will set up a search box with an autocomplete based on the results of the search. We will use the following:

This is the first part of a two part series on integrating these technologies into your rails application.

Search can be implemented in many ways. You can create the corresponding SQL queries to get the results or you can use a search engine designed for this task. Apache Solr is an opensource search engine written in Java. Its major features include powerful full-text search, hit highlighting, faceted search, near real-time indexing and so on. 

Read more >>
Tagged with: , , , ,
Posted in Javascript, Ruby on Rails

Categories