background preloader

Ruby on Rail

Facebook Twitter

Databases & Rails: Week 6 Data Visualization with Javascript. When most people think of great web sites they don’t think of borring pages that have to refresh every time you click something, they think of sites filled with dynamic like buttons, and moving charts and graphs.

Databases & Rails: Week 6 Data Visualization with Javascript

While I always encouraging having a solid site before adding any javascript extras, sometimes javascript is just the best tool for the job. Recap of last Week 5 , Quiz, & Solutions This week we’ll cover the difference between class and instance methods in Ruby, then we’ll give you a quick intro to javascript and jQuery. Next we’ll talk about the asset pipeline in Rails and what it’s used for. Finally we’ll wrap up with some info on the project. The exercise this week is all about adding some pretty awesome charts and AJAX functionality to our site with javascript! Ruby class & Instance Methods. Chapter 5: Filling in the layout. 5.1 Adding some structure The Rails Tutorial is a book on web development, not web design, but it would be depressing to work on an application that looks like complete crap, so in this section we’ll add some structure to the layout and give it some minimal styling with CSS.

Chapter 5: Filling in the layout

In addition to using some custom CSS rules, we’ll make use of Bootstrap, an open-source web design framework from Twitter. We’ll also give our code some styling, so to speak, using partials to tidy up the layout once it gets a little cluttered. When building web applications, it is often useful to get a high-level overview of the user interface as early as possible. Throughout the rest of this book, I will thus often include mockups (in a web context often called wireframes), which are rough sketches of what the eventual application will look like.2 In this chapter, we will principally be developing the static pages introduced in Section 3.1, including a site logo, a navigation header, and a site footer.

<! <! Opal: Ruby in Your Browser, the Basics. I love Ruby, and it is my go-to language for building web applications.

Opal: Ruby in Your Browser, the Basics

Unfortunately, when dealing with the browser, Javascript is a necessary evil. As you can see, I am not a huge fan. Ruby on Rails for PHP and Java Developers - Deepak Vohra. Easier Nested Layouts in Rails 3/4. A layouts recap Any non-trivial web application will have multiple HTML layouts.

Easier Nested Layouts in Rails 3/4

For example, a login page may use a simple layout with no header and footer, whereas authenticated pages will have navigation bars and breadcrumbs. Public pages like documentation and privacy policy may use yet a different layout. Rails offers a basic solution for this in the form of layout templates. Create a layout file with the boilerplate you need, then yield to the actual dynamic content that is being rendered: <html><head> ... You can have as many layouts as you’d like, and Rails makes use of convention over configuration to automatically pair up layouts with corresponding controllers of the same name. Nested layouts, the (awkward) Rails way So far so good. Every page in the app needs the standard HTML boilerplate with our common stylesheets, JavaScripts.

Some frameworks call this template inheritance. Layouts and Rendering in Rails, Season 2. Unholy Rails: Adding JavaScript to Rails. By Daniel Kehoe Last updated 31 December 2012 Rails and JavaScript topics: How to include external JavaScript files and jQuery plugins in Rails 3.1 or newer.

Unholy Rails: Adding JavaScript to Rails

Using page-specific JavaScript in Rails. Organizing JavaScript files. Passing parameters to JavaScript. Layouts and Rendering in Rails. 1 Overview: How the Pieces Fit Together This guide focuses on the interaction between Controller and View in the Model-View-Controller triangle.

Layouts and Rendering in Rails

As you know, the Controller is responsible for orchestrating the whole process of handling a request in Rails, though it normally hands off any heavy code to the Model. But then, when it's time to send a response back to the user, the Controller hands things off to the View. It's that handoff that is the subject of this guide. In broad strokes, this involves deciding what should be sent as the response and calling an appropriate method to create that response. 2 Creating Responses. Ruby on Rails Tutorial. My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP (Google me to read about the drama).

Ruby on Rails Tutorial

This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on Rails Tutorial is what I used to switch back to Rails again. Though I’ve worked my way through many Rails books, this is the one that finally made me “get” it. Everything is done very much “the Rails way”—a way that felt very unnatural to me before, but now after doing this book finally feels natural.

This is also the only Rails book that does test-driven development the entire time, an approach highly recommended by the experts but which has never been so clearly demonstrated before. Finally, by including Git, GitHub, and Heroku in the demo examples, the author really gives you a feel for what it’s like to do a real-world project. The linear narrative is such a great format.

Enjoy! Derek Sivers (sivers.org) Founder, CD Baby. An Introduction to Web Development Using the Ruby on Rails Framework. Click here to view the complete list of archived articles This article was originally published in the Fall 2006 issue of Methods & Tools.

An Introduction to Web Development Using the Ruby on Rails Framework

Transactions In Rails - Mark Daggett's Blog. Recently I was tasked to write tests for the transactions of an existing application.

Transactions In Rails - Mark Daggett's Blog

This gave me the opportunity to learn more about the codebase, while also improving the test coverage. Generally, most of the transaction code looked fine. However, there were some instances where transactions were used incorrectly or inefficiently. I assumed this is just because of a misunderstanding of how transactions work within Rails, and so I thought iʼd take some time and give an overview of the common errors I found and some best practices for using transactions in Rails.

Let me also state at the beginning that most of these examples are not my own, they come directly from the Rails source, which give example usages of applying transactions RTFM FTW. Reasons for transactions We use transactions as a protective wrapper around SQL statements to ensure changes to the database only occur when all actions succeed together.

Transaction Rollback Triggers Note: The bang modifier (!) Transaction Gotchas.