Apr 28

Date published: 4-28-2014

Rails version: 4.0.0

Layouts

One of the good things about using Ruby on Rails is that you can setup a basic site layout and it will automatically be applied to every page on the site. If you’ve ever worked on a site that didn’t use layouts, then you know what a timesaver this can be. Rather than having to modify every single page when you want to make a change to the header for example, you make one change in the layout file, and all the pages on your site will now use the updated header. There may be times when you want to disregard the default layout or use a different one entirely, such as when the user wants to print something and wants their information without all the extraneous elements like the header, footer, or navigation sidebar. Continue reading »

Tagged with:
Mar 31

Date published: 3-31-2014

Rails version: 4.0.0

Counting with Javascript

It’s common in Rails apps that take input to use text areas to enter large blocks of text. It’s also common to have a limit on the amount of text that can be entered to ensure the database doesn’t get filled with pointlessly long posts or comments. It’s easy to put a validation in a model to limit the amount of text that can be entered, but it’s nice to give feedback in the view to show how much of the limit the user has already used. Continue reading »

Tagged with:
Mar 17

Date published: 3-17-2014

Rails version: 4.0.0

Staging server

When creating and deploying web apps with Rails, it’s a good idea to have a staging server that is identical to the production server where you can test out changes before making them live. That way you can test out the application in an environment that will be like what your users will be using but without making changes to the live application or its database. I’ll be setting up a staging server on Heroku to show the changes you’ll need to make to your Rails project to get it up and working. Continue reading »

Tagged with:
Mar 03

Date published: 3-3-2014

Rails version: 4.0.0

Pagination

It’s common on web sites to have large numbers of records in the database. It’s not always useful to see all the items in the database at the same time as it could take a long time to load and involve a lot of scrolling to find the information we want. This is where pagination can be used as a helpful way to divide a set of results into chunks that are easier to use. A good example of pagination that is familiar to any web user is the set of links at the bottom of the page of search engines like Google. It has links to go to the next and previous pages and information about how many pages there are to look through. Continue reading »

Tagged with:
Feb 17

Date published: 2-17-2014

Rails version: 4.0.0

Tags

One common element used by web sites is the tag. Blogs make extensive use of them, and on this blog you can find the list of tags associated with each post and a tag cloud in the toolbar on the right to see a list of all tags and how often they are used. In this tutorial, we’re going to look at a popular gem for adding tags to a model. Continue reading »

Tagged with:
Feb 03

Date published: 2-3-2014

Rails version: 4.0.0

RSpec

In my last tutorial I demonstrated how to setup tests for a model using the testing framework included with Rails. In this tutorial, I want to try out a different testing framework called RSpec to see how it compares to what we did before. RSpec is one of the most popular ways to test Rails apps, so if you work with Rails, you’re bound to run into projects that use it for testing. Continue reading »

Tagged with:
Jan 20

Date published: 1-20-2014

Rails version: 4.0.0

Testing

One common task that developers should do when working on a project is to create tests that can be run to ensure that when we add new functionality to the project that it won’t break things that already exist. Rails already has a comprehensive test structure built in, and there are a ton of other resources that other developers have created to make testing easier. In this tutorial, I’m going to create tests for a basic User model using Rails’ test framework. Continue reading »

Tagged with:
Jan 06

Date published: 1-6-2014

Rails version: 4.0.0

Custom interface

One of my previous tutorials showed how to install and use CKEditor to give all textareas a graphical user interface. We only scratched the surface of what it’s possible to do with CKEditor, so I’m going to return to the subject and show how to customize the user interface. Continue reading »

Tagged with:
Dec 23

Date published: 12-23-2013

Rails version: 4.0.0

Enumeration

One tool that programmers use fairly often to store information is the enumeration. It’s most often used to store the state of objects in the model so the program knows how to interpret other data in that model. As common as enumerations are, it’s surprising that Rails doesn’t have a standard for handling it. In this tutorial, we’ll learn how to create an enumeration that follows Rails conventions and symbols. Continue reading »

Tagged with:
Dec 09

Date published: 12-9-2013

Rails version: 4.0.0

URLs and readability

One consideration when creating web sites with Rails that a developer should consider is how easy it is to navigate the site. One convention Rails uses for URLs is to have a path that includes the name of the class from the model along with the id of whichever specific item we want to look at. This is great for Rails as it makes it obvious which item we want to search for in our model, but from a human readability standpoint it’s not that great. This tutorial will show you what to add to your application to make your URLs more readable.

Pretty URLs

Pretty URLs

Continue reading »

Tagged with:
preload preload preload