background preloader

RAILS STUFF

Facebook Twitter

GEMs

MIGRATION. ACTIVE RECORDS. INSTALL. Ruby: Counting occurrences of an item in an array / enumerable. Ratyrate: Add Rating to Your Rails App. Basic AJAX in Ruby on Rails - RichOnRails.com. Additional related article content can be found in the right sidebar.

Basic AJAX in Ruby on Rails - RichOnRails.com

This article will teach you the basics of AJAX in Ruby on Rails. Updated on August 31st, 2015 for Rails 4.2 and Bootstrap 3.x! Quite often in the past, we had to result to a ton of different javascript to perform many different AJAX operations, luckily Ruby on Rails makes AJAX structured and easy. This article will teach you the basics of using AJAX in your Rails application. In this example, we will use twitter bootstrap to add some styling and functionality to our app. Gemfile: gem 'bootstrap-sass', '~> 3.3.5.1' Next, run a bundle install. Terminal Commands: bundle install Next, create a file in your assets stylesheets folder called bootstrap_config.scss and add the following code. app/assets/stylesheets/bootstrap_config.scss: @import "bootstrap-sprockets";@import "bootstrap";

Understanding Polymorphic Associations in Rails. Polymorphic associations can be tricky to understand and many times one can get confused about when to use them, how to use them and how they are different from other associations.

Understanding Polymorphic Associations in Rails

In this article we will go over these issues. Introduction Active Record Associations are one of the most important features of Rails. Polymorphic association is part of these associations. Ruby on Rails Guide states “with polymorphic associations, a model can belong to more than one other model, on a single association”. Basics While writing some rails application you will run into situations when you have model associations that seem to be similar, for example lets assume you have Course and Lab models in your application. Brush up Your Knowledge of Rails Associations. Rails 5 is coming very soon (it’s currently at RC1), so while preparing for this major version, it is high time to revisit the basics.

Brush up Your Knowledge of Rails Associations

Today we are going to discuss ActiveRecord associations. Associations make it much easier to perform various operations on the records in your code. There are multiple types of associations available: Infinite Scrolling in Rails: The Basics. Pagination is a very common and widely-used navigation technique, and with good reason.

Infinite Scrolling in Rails: The Basics

First of all, consider performance. Loading all the available records in a single query can be very costly. Moreover, a user may be interested only in a couple of the most recent records (i.e., the latest posts in a blog) and does not want to wait for all records to load and render. Also, pagination makes reading the page easier by not flooding it with content. Nowadays, many websites use a slightly different technique, called infinite scrolling (or endless page).

In this article, I am going to explain how to implement infinite scrolling in place of classic pagination. First, we will prepare our demo project, implementing basic pagination using the will_paginate gem. The provided solution will fallback to the default pagination if a user has javascript disabled in the browser.

Other items that will be covered: The working demo can be found at. Infinite Scrolling with Rails, In Practice. In the predecessor to this article, we set up a very simple blog with demo posts and implemented infinite scrolling instead of simple pagination.

Infinite Scrolling with Rails, In Practice

We used will_paginate and some javascript to achieve this task. The working demo can be found on Heroku. The source code can be found on GitHub. Today, let’s implement a “Load more” button instead of an infinite scrolling. This solution may come in handy when, for example, you have some links inside the footer and infinite scrolling causes it to “run away” until all the records are loaded. To demonstrate how this can be done, make the following changes to PostsController: posts_controller.rb def index get_and_show_posts end def index_with_button get_and_show_posts end private def get_and_show_posts @posts = Post.paginate(page: params[:page], per_page: 15).order('created_at DESC') respond_to do |format| format.html format.js endend And add a route:

Ruby on Rails: Download. Infinite Scrolling. Infinite Scrolling with Rails, In Practice. GitHub - plataformatec/simple_form: Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup. Rails Application Layout. By Daniel Kehoe Last updated 3 August 2014 Rails application layout for HTML5.

Rails Application Layout

Shows how to set up an application layout with navigation links, messages for alerts and notices, and CSS styling for Rails. If You Are New to Rails If you’re new to Rails, see What is Ruby on Rails? What is the RailsApps Project? This is an article from the RailsApps project. Background The default application layout is where you put HTML that you want to include on every page of your website. Every Rails application needs a well-designed application layout. Rails will use the layout defined in the file app/views/layouts/application.html.erb as a default for rendering any page. HTML5 Boilerplate The well-known HTML5 Boilerplate project has been recommending “best practice” tweaks to web pages since 2010. Front-end Frameworks This article shows how to set up a simple application layout with navigation links, messages for alerts and notices, and CSS styling for Rails. Change data in migrations like a boss – Rails Guides.