Friday, April 1, 2016

Integrating Rails and Bootstrap

Introduction

Integrating Rails and Bootstrap. Bootstrap rails step by step. I will show you how to integrating Rails and Bootstrap, Let's get started.

Get Started

First, create sample rails, like this
rails new bootstrap_rails
generate scaffold Product
rails g scaffold Product name:string price:decimal notes:text

Migrate change database
rake db:migrate

We need some data to our app, lets make seed data. Put the following lines in your db/seeds.rb file.
then run the following in your terminal/command prompt:
rake db:seed

Now, let's make simple route :

In your config/routes.rb file, add root 'products#index':

now run the server:

rails s

Now when you visit the app in your browser, at http://localhost:3000, you should see this:


How to Integrate with Bootstrap


Install the ruby gem for bootstrap


Autoprefixer (autoprefixer-rails) is optional, but recommended. It automatically adds the proper vendor prefixes to your CSS code when it is compiled.

Now run

bundle install

Import Bootstrap CSS assets

We will rename app/assets/stylesheets/application.css to app/assets/stylesheets/application.css.sass. Then we can import the Bootstrap assets in your newly-renamed application.css.sass file.




When you compile, imported assets render a compiled version of their contents where the @import statement was found.

Import Bootstrap Javascript assets

You need to add:


to your app/assets/javascripts/application.js file.

It is important that it comes after:
//= require jquery
Your file should look like this:


It is also important that:

//= require_tree .
is the last thing to be required.

The reason is, //= require_tree . compiles each of the other Javascript files in the javascripts directory and any subdirectories. If you require bootstrap-sprockets after everything else, your other scripts may not have access to the Bootstrap functions.


Let's make view beuty like bootstrap view.
Edit your layouts/application.html.erb

Your view will like this:


Oke, let's edit your products/index.html.erb

The result :


Congratulation

That's it, simple tutorial how to integrate Rails and Bootstrap. You can download source code in my github
Baca selengkapnya

Saturday, March 19, 2016

Creating the First Application Ruby on Rails

Creating the First Application Ruby on Rails

Creating the First Application Ruby on Rails. The best way to use this guide is to follow each step as it happens, no code or step needed to make this example application has been left out, so you can literally follow along step by step.

By following along with this guide, you'll create a Rails project called blog, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed.

Installing Rails

Open up a command line prompt. On Mac OS X open Terminal.app, on Windows choose "Run" from your Start menu and type 'cmd.exe'. Any commands prefaced with a dollar sign $ should be run in the command line. Verify that you have a current version of Ruby installed:
A number of tools exist to help you quickly install Ruby and Ruby on Rails on your system. Windows users can use Rails Installer, while Mac OS X users can use Tokaido.
Baca selengkapnya

Thursday, March 17, 2016

Pagination Rails using Kaminari gem

When we work with just couple of records, it's easy to simply list them all on the index page. But, what happens when we have more than two, let's say 100 records? What if we have 1000? How about 1 million? If we try to list all records from the database on a website at once, not only it will be a lot of load on the database, download will take much longer time, but it's likely that user's browser will crash.

Step 1: Add Kaminari and Bundle Gems

First, add kaminari to the Gemfile


gem 'kaminari'

gem 'kaminari-bootstrap'

because we use bootstrap for style, so kaminari-bootstrap are nicely styled.

$ bundle install

Baca selengkapnya

Sunday, March 13, 2016

Introduction

Introduction

1. Intro

This website is designed for medium ruby on rails tutorial. Contains articles, tutorials, tips and tricks ruby on rails from my own experience or from several websites on the internet.
Learning to build a modern web application is daunting. Ruby on Rails makes it much easier and more fun. It includes everything you need to build fantastic applications, and you can learn it with the support of our large, friendly community.

Ruby on Rails is open source software, so not only is it free to use, you can also help make it better. More than 4,200 people already have contributed code to Rails. It’s easier than you think to become one of them.
 "quoted from the official web ruby on rails"

2. What is Rails?

Rails is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Experienced Rails developers also report that it makes web application development more fun.

Rails is opinionated software. It makes the assumption that there is the "best" way to do things, and it's designed to encourage that way - and in some cases to discourage alternatives. If you learn "The Rails Way" you'll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience.

The Rails philosophy includes two major guiding principles:

  • Don't Repeat Yourself: DRY is a principle of software development which states that "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." By not writing the same information over and over again, our code is more maintainable, more extensible, and less buggy.
  • Convention Over Configuration: Rails has opinions about the best way to do many things in a web application, and defaults to this set of conventions, rather than require that you specify every minutiae through endless configuration files.


So, Keep up date with me and with ruby on rails.
Baca selengkapnya