background preloader

Rails

Facebook Twitter

SMACSS and Rails – A Styleguide for the Asset Pipeline • 55 Minutes Blog. If you’re already familiar with SMACSS, skip ahead to the Rails styleguide. SMACSS principles SMACSS (Scalable and Modular Architecture for CSS) is a set of CSS guidelines created and promoted by Jonathan Snook, who also offers an e-book of the same name. A generous portion of the book’s contents is available for free at smacss.com.

If you aren’t already familiar with SMACSS, I highly recommend the book; it’s a quick read. Let’s recap some core principles of SMACSS before we dive into the Rails implementation. Categorization Base styles are the default styles for HTML elements (h1, p, pre, etc.).Layout styles are grid and other reusable layout classes. Guidelines Avoid IDs in CSSMinimize the depth of CSS selectorsUse classes to define visual presentation patterns1 SMACSS versus Rails conventions As an experienced Rails developer, you may notice that many of the SMACSS principles contradict what are typically considered best practices in Rails.

A SMACSS styleguide for Rails projects Filenames. Getting Started With Ruby On Rails. Four Ways Ruby on Rails Can Help You. Ruby on Rails, an open source web development framework, has revolutionized the way we create web applications. By giving developers the necessarily tools and components needed to build powerful apps in an intuitive development environment, RoR makes development more efficient and less troublesome. In this article, we discuss some of the ways Ruby on Rails can help you in rapidly building fully-featured web-based applications. 1. Rapid Development and Prototypes Issues caused by old techniques When developing a website for a client, I want to concentrate on the clients needs i.e. the domain problem at hand.

How Rails can help Ruby on Rails uses a concept called Convention over Configuration which makes you follow conventions while you’re coding, leaving you with little configuration to do. 2. The main problem here, is separating the view markup from the business logic. How Rails can Help As with many web frameworks, Rails uses the MVC compound design pattern to solve this problem. 3. 4.

Asset Pipeline for Dummies - coderberry. The Rails asset pipeline is very powerful, but often misunderstood. At the Utah Ruby User Group, most of the attendees aren’t sure how to use it fully in their Rails app. It’s considered as one of the magic features that Rails offers. I admit that I was confused as well and took it’s magic for granted.

Not any longer. I reference the word asset a lot in this article. An asset is a file that is to be included in your Rails application (JavaScript, CSS, Image, etc). In this article, I want to simplify the asset pipeline so it is better understood. Purpose The asset pipeline has three goals: precompile, concatenate and minify assets into one central path. Moving Parts The asset pipeline is powered by two technologies: Sprockets and Tilt, the latter being a dependency of the former (look at your Gemfile.lock if you don’t believe me). Tilt is the template engine that Sprockets uses. Asset Paths Rails applications default to having three possible asset paths. The Manifest Usage Misconceptions No.

How to Create a Blog from Scratch Using Ruby on Rails. This tutorial shows you how to create a basic blog using Ruby on Rails. By covering the design aspects of a Rails web application, it makes it easier to understand the concepts behind Rails and how they fit together. The first part of this article Getting Started with Ruby on Rails: Installation, shows you how to install Ruby on Rails. Brief Overview of Ruby on Rails Ruby on Rails is a framework for the Ruby language, which is used for rapid development of web applications. It does this by allowing you to concentrate on solving your clients’ problems and not getting caught up in building an infrastructure to support your clients problem. Let’s face it, you don’t want to build database access layer every time you start a new project.

Neither will you want to implement a fully functioning MVC pattern on a regular basis. A Few Words About MVC It’s worth mentioning MVC (Model-View-Controller) because it can be one of the factors that discourages people from trying frameworks like Rails. Model. Ruby on rails - How can I display every 4th product with different markup. ActionView::Helpers::TextHelper. The TextHelper module provides a set of methods for filtering, formatting and transforming strings, which can reduce the amount of inline Ruby code in your views. These helper methods extend Action View making them callable within your template files. Sanitization Most text helpers by default sanitize the given content, but do not escape it. This means HTML tags will appear in the page but all malicious code will be removed. Let's look at some examples using the simple_format method: simple_format('<a href=" # => "<p><a href=\" simple_format('<a href="javascript:alert(\'no!

\')">Example</a>') # => "<p><a>Example</a></p>" If you want to escape all content, you should invoke the h method before calling the text helper. Methods excerpt highlight pluralize reset_cycle truncate word_wrap Included Modules Instance Public methods The preferred method of outputting text in your views is to use the <%= “text” %> eRuby syntax. Options. Links - link_to image_tag with text in rails. A Wealth Of Ruby Loops And Iterators. I remember when I first started looking at Ruby, I’d be browsing some code and see yet another way of looping/iterating over stuff. Whenever that would happen I would think, “…Ruby sure has a lot of different ways to iterate over things”, but I also remember wishing that someone would just put all the different ways to loop and iterate over stuff together so that you don’t have to discover them in a piecemeal fashion.

Most resources I’ve seen tend to gloss over this a little bit by introducing the while loop and the each iterator and quickly moving on to more interesting things, expecting you to discover the rest on your own (nothing wrong with that by the way). As you may have guessed from my recent posts on Ruby method arguments (and more advanced method arguments), the Ruby case statement and others, I am kind-of discovering Ruby in my own way and looking more closely at things that I find of interest.

Ways To Loop Over Stuff In Ruby Unconditional Looping With Loop The While Loop. Learn Ruby, Ruby on Rails tutorial. Ruby on Rails is the web development framework of the moment, powering GitHub, Twitter, Hulu and many more successful apps and websites. The arrival of Rails 4 is the perfect time to learn it. SitePoint’s newest ebook, ‘Jump Start Rails’, from Andy Hawthorne, will get you up to speed with Ruby on Rails in just a weekend. Andy has also prepared the ‘Build your first Rails’ app online course to take you from creating a complete Ruby on Rails 4 app with a log in system all the way to deploying it to Heroku, a leading Rails application hosting environment, in a couple of hours.

Also, our all time great, 10 part tutorial from Patrick Lenz can be found here: Learn Ruby on Rails: the Ultimate Beginner’s Tutorial. If you are looking for more advanced topics such as this great Introduction to Sass in Rails, head over to RubySource for fresh tutorials and to discover new Ruby gems. Editor-in-chief, SitePoint & Learnable.