Rails_standards/README.md at rails-3-2 · hopsoft/rails_standards. Diary of a Rails rescue project, part 2: Testing. April 16, 2013 As mentioned previously, I’ve been spending spare cycles getting an outdated Rails application up to speed. Aside from the outdated versions of Rails and pretty much every gem used by the app, there’s a glaring problem: No usable tests. Without tests, I can’t be certain of what the application is supposed to do.
What’s more, I can’t be sure that the rather massive changes I’m making to the code’s underpinnings won’t break functionality. While the previous developer did have some tests in place, I quickly lost faith in them: On first run I got a number of deprecation warnings, then 60 percent of the provided tests failed. Upon further inspection, it became evident that most of the files in the spec/ directory were stubs generated by the likes of rails generate scaffold. To address this, I decided to write out my own high level tests of the application’s core functions. I got a handle on what parts of the application were being touched by each given user interaction. Buy now. Diary of a Rails rescue project. March 21, 2013 I recently picked up a rescue project.
It’s pretty gnarly–the application was, I believe, originally written in Rails 2.3 (possibly older), was updated to Rails 3.0 at some point, and sat unattended for most of last year. When major security issues hit Ruby and Rails the past few months, there were concerns that the application would have to be taken offline if action weren’t taken. So I agreed to the work. Rescue projects are unique challenges. So what I’d like to present here, over time, is a log of the work. Rails 3.2.12, with an eye on Rails 4 (currently at 3.0.6!) My general plan of attack is to get the application up to as current of a release of Rails 3.0 as I can, then build out tests against that.
I’m not sure where this journal of the work will head, but honestly, after writing and maintaining a living book heavy with code samples for a year, I’m ready to try something different. So let’s start with my development setup. Gem 'devise', '~> 1.3.4' Next time Buy now. List of 40+ tutorials on how to create an API. Exercism.io. BBC-News/wraith. Leveraging your Intuition. Have you ever felt certain of something, despite not having any evidence to back up your hypothesis?
That was probably your intuition guiding you. For good reason (i.e., intuition is often quite wrong about things that you aren’t fully educated on or internalized), people spend a lot of time learning how to set their intuition aside. I know there’s no way I would have passed Calculus or Chemistry without ignoring mine. However, once you reach a certain familiarity with a subject, your intuition becomes a powerful and useful tool. I believe the transition back to trusting your intuition is fairly organic for most people. The benefit of having an intuition that you can trust is that the effort becomes unconscious and frees your conscious mind to focus on other things. The downside is that it’s far from perfect. Personally, I’ve come to rely heavily on intuition for dealing with architecture and organization.
My Experiences with Ruby off Rails. I was recently pointed to Ben Singelman’s post on Why Nobody Should Use Rails For Anything, Ever. We seem to never get enough of arguing about application frameworks: I’m not going to do that. What irks me is when Ruby get thrown out with the Rails bathwater. As one commenter on Singleman’s post demonstrates: “Interesting perspective. I agree on your general points — Ruby’s fine at an MVP stage I think, but when it comes to creating something for market, it just falls over.” (This despite the second sentence of the post stating “Independent of ruby, I see Rails as the emperor with no clothes on.”) I see posts like this a lot. Don’t pick on Ruby just because you don’t like Rails Despite making use of Ruby since 2004, I’ve never personally written a Rails app for a customer. I was an early advocate for Rails, discovering it in 2005 and attending RailsConf in 2007. Language and framework wars aside, there are many other ways to make Ruby useful.
SchmidtHappens | Evaluating Different Ruby and Rails Versions with RVM. If you've ever had to test an application that you are building with different versions of Ruby or Rails then you know how frustrating it can be. RVM aims to erase that frustration by making it incredibly easy to install multiple versions on the same development machine.
The first thing that you will need to do is install RVM. To do this open a terminal and enter in the following command (please note, you will need to make sure you have git installed): bash < <(curl -s Once the install finishes you will be instructed on how you can update your .bash_profile file with a load path to the rvm executable. Great, now that we've gotten that out of the way it's super simple to install new Ruby versions. To use an installed Ruby use the following (substitute the version you want): Wondering which Ruby versions are available for download? Want to know which you already have installed? What About Rails? Rvm gemset create rails31 Something missing? 10 Ruby on Rails Best Practices.
If you’re new to Ruby on Rails, one of the most daunting aspects is knowing what’s the preferred way of accomplishing a given task. While a lot of techniques and libraries have come and gone as the community’s preferred way of doing something, there are some best practices that remain, and can lead to writing the cleanest, most secure and maintainable Rails code possible. Listed here today are ten of the most popular and useful best practices you can use as a Ruby developer. Fat Model, Skinny Controller Arguably one of the most important ways to write clear and concise code in Ruby on Rails, the motto “Fat Model, Skinny Controller” refers to how the M and C parts of MVC ideally work together. Namely, any non-response-related logic should go in the model, ideally in a nice, testable method. Meanwhile, the “skinny” controller is simply a nice interface between the view and model. Let’s look at a simple example. You can change it to this: Reusable Scopes and Relations And in Rails 2:
BridgeUtopia | Ruby on Rails & Mobile Application Development. Drastically Improving Your Code With Messaging as a Programming Model. HTTP/HTTPS traffic recording. Learn. It often feels like "best practices" have a shelf-life of a few months before being replaced by better ideas. Between Rails’ constant changes and a never-ending stream of new gems and philosophies, it’s a real challenge to keep up with the state of the art. Stay on top of it by reading the source of the Learn app itself, watching the thoughtbot team contribute to it, reading our books (which also come with high quality source code), and watching screencasts on vim, development tools, and more. A fallback plugin for HTML5 Web Notifications. Check the code on Github The code is available on GITHUB.Check the repository wnf. In a recent post on this blog, I wrote about the new HTML5 Web Notification api. Once I discovered this new feature, I couldn’t wait to use it in a real project… the only problem was that currently the support for native web notifications really sucks.
Should this distract me from my intent? No way! So, I wrote a jQuery plugin (the first I published too) to handle notifications on browsers which don’t support the native web notification api. Not just another notification plugin I know what you’re thinking: [sarcasm] Oh, yet another ( * ) plugin for notifications! Why this is different? The plugin name is wnf: this is the acronym of Web Notification Fallback (sometimes I have a lot of imagination, and sometimes no). As you can see in the picture there are two main differences between the two notifications: Caveat Usage I prepared a small demo page, where you can play with the plugin, and learn how to use it.
Start using Web Notification. Recently I started to use in some personal projects the native browser notifications… if you didn’t hear this term before, you are in the same situation I was more or less three weeks ago. So you have to know that web notifications allow to alert the user outside the context of a web page of an event, without the need to use third party plugin.
Sounds great, right? So, if you are interested this post will guide you through the discovery of web notifications. Ask the user for permission The first thing necessary to show user a notification message is to ask him the permission. window.Notification.requestPermission(function(grant) { }); Currently, this snippet works only when is inserted inside a click event handler function. Default: it is equivalent to denied, but the user has made no explicit choice thus far.denied: notifications won’t be displayed.granted: notifications can be displayed. After the user expressed his preference the browsers store this information. Show the notification. Coding Online – Reviews of the most interesting services. Recently many services like jsfiddle are came out… to be sincere I actually don’t know neither if jsfiddle was the first. What is for sure is that until now I used jsfiddle to run the demo of this blog. Recently I did a little research over these services… I would like to use the one that fits better my needs.
This post summarize the results of my research. jsFiddle jsFiddle was the first web app I used to create small demo online (“could make a fiddle?” Is now a common expression); it is a very complete service, and I’m overall happy of it. It has all the features that you could expect to find in a service of this kind. Its defects, you say? Download of the demos that you createdautorun after an edit Codepen Codepen is probably the most complete of the services I tryed. However the thing that impressed me the most is the community around codepen.
Also Codepen could be still improved, for example adding the possibility to download the demos that you created. jsBin Dabblet Conclusion. Web Workers cheatsheet. I continue the series of posts about the new goodies of HTML5 (I hope that you have not missed “Start using Web Notification”, and “Geolocation api cheatsheet”) with this article, that collects the main methods to work with javascript Web Workers. What are Web Workers? Browsers are single-threaded programs; this causes that the scripts executed in every application run together in a single UI thread. DOM event, xhr request or the javascript setTimeout function give us just the illusion that there are more things happening at the same time. Traditionally this was a limitation, and it is for this reason that often the most demanding functionalities in terms of computational power were managed server side. Web Workers API defines a way to run javascript scripts in the background, in parallel with the main page, and allows to overcome the traditional limitations of the browsers.
The HTML5 Specification talks of two different types of Web Worker: Dedicated Web Worker and Shared Web Worker. Rails in Realtime — LayerVault Blog. Come #pairwithme on Ember.js! Pair Programming with Ember.js - Episode 2. 11 Things You Didn't Know About Mountain Lion. OS X Mountain Lion includes over 200 new features for your Mac, but some of the major ones aren’t mentioned on the official webpage. If you go looking around in nooks and crannies, you might just find some valuable minor features that you’d never even thought of. I’ve been using the operating system since its first developer preview was released and there are a few nifty features that lie tucked away and out of plain sight.
Read on to see what they are! Chess is Multiplayer via Game Center Selecting a match with a human over the Internet. Do you like a good game of chess? Time Machine Supports Backing Up to Multiple Destinations One of my favorite features of OS X is Time Machine. Mountain Lion provides a solution to this issue by giving you the option to back up data to more than one destination using Time Machine. You Can Finally Search in Launchpad Searching for "midi" in Launchpad. Thankfully, Apple added the latter in OS X 10.8. Progress Bars for Transfers or Downloads. Important Considerations When Building Single Page Web Apps. Single page web applications - or SPAs, as they are commonly referred to - are quickly becoming the de facto standard for web app development.
The fact that a major part of the app runs inside a single web page makes it very interesting and appealing, and the accelerated growth of browser capabilities pushes us closer to the day, when all apps run entirely in the browser. Technically, most web pages already are SPAs; it's the complexity of a page that differentiates a web page from a web app. In my opinion, a page becomes an app when you incorporate workflows, CRUD operations, and state management around certain tasks. You're working with a SPA when each of these tasks take place on the same page (using AJAX for client/server communication, of course).
Let's start with this common understanding, and dive into some of the more important things that should be considered when building SPAs. I will expand on each of the points above in the following sections. Picking an Application Framework.
Rails 4. Model. UI & UI Libs. Templating. Rails Automate Workflow. Rails Tuts. Rails/Angular - Github, etc. Hey Underscore, You're Doing It Wrong! Three Keys to Successful Single Page Web Applications. You've got 100 milliseconds for your web application to engage your users before they start to feel disconnected from the app. That's 1/10th of a second. After a whole second, you're starting to lose users completely. This simple fact is motivation enough for many to employ usage of single page web applications, and in this presentation from HTML5DevConf, Josh Powell will share three keys to doing so successfully. Moving logic and data to the client and loading only changes are important pieces of the puzzle, but to make your SPA performant for the user as well as the developer means you'll have to address certain issues with SEO, analytics, error tracking, and more.
Join Josh as he walks you through elegant solutions to these challenges. Ready to start coding faster with HTML5? We have a bunch more resources for HTML developers, and we also offer some awesome training courses.
General. Git/Heroku. Ruby on Rails & AngularJS: Resources | Dillon Buchanan. I’m a huge fan of AngularJS and an even bigger fan of Ruby on Rails. However, one of the gripes I have with AngularJS is the fact it lacks great documentation. Stuff seems scattered, especially when it comes to the magical ‘Resource’ module. To test the feasibility of AngularJS when using Rails I created a simple project to demonstrate an all AngularJS front-end communicating to a Rails back-end via the Resource module.
The following write up starts with setting up Rails and moves into setting up Angular later. Source and Live Demo You can find the entire project here on Github and the live demonstration of the project here on Heroku . Setting Up Rails Setting up the Rails back-end was the easy part. The first thing I did, as I like to do, is add some of my favorite gems that will help ignore the tedious parts of rails and get to the exciting parts: If you’ve never heard of these Gems I suggest you click on their links above and check them out.
Models Controllers Routes Rails Layout View Fin.
Testing.