background preloader

Posts to READ

Facebook Twitter

Presenters to Widgets with ActiveModel. Rails offers an easy way to render objects in a view that are automatically associated with their own partials. With ActiveModel::Conversion, you can quickly build widgets out of classes (models or presenters or other). The Problem In a recent project, we had several little status/info blocks that we wanted to render on a page.

Each block required different model data. In the controller, as we started writing code to fetch all the right data and put it together, we quickly realized that things were going to get ugly. You can see that as we added more items to put on the page, both the controller and view got bigger and more complex. Reduce the amount of work done by the controller to prepare data for the viewsBuild an easy way to render the different chunks of data as separate widgets The Solution Presenters The first step is to build some presenters. Peter Marklund's Home : Rails Tip: Inserting NULL to the Database Instead of Empty Strings. Content_tag inside content_tag. Kanna (Guest) on 2013-08-13 13:51 Hi i tried content_tag inside content_tag bu its not working <%= content_tag(:h1,"Arrange"+content_tag(:span,"Demo"))%> i want like this type <h1>Arrange <span>Demo</span></h1> plz help. bye kingston.s (Guest)

content_tag inside content_tag

Amazon Releases aws-sdk, An Official AWS SDK for Ruby Developers. Amazon has unveiled an official Ruby SDK for AWS!

Amazon Releases aws-sdk, An Official AWS SDK for Ruby Developers

Amazon.com's Amazon Web Services has been a rip-roaring success since its first publicly-available service, S3 (Simple Storage Storage), was released in 2006. It has since expanded to about 20 services in all, the most popular being S3 and the "elastic compute cloud" EC2. There have previously been unofficial Ruby libraries for interfacing with Amazon's many services, including PoolParty, right_aws, and Marcel Molina's awesome aws-s3, and Amazon even released some bits and pieces of Ruby code before, but the new aws-sdk gem represents a stronger effort to have a single, official cohesive library for Rubyists using AWS. TUTORIAL: Ruby on Rails 4.0, Amazon S3, Paperclip and Heroku - Direct Upload with the s3_direct_upload gem.

DRYer, neater Rails before_filters using classes. Recently I was working on a project which required various permissions for each controller.

DRYer, neater Rails before_filters using classes

A user could have permission to access one feature of the site but not another. Here’s a great tip for keeping your rails controllers simple and DRY when working with multiple before filter conditions. The before_filter method takes not only a method name as an argument, it can also take custom class objects as an argument. Here’s an example: class OrdersController # run this before filter on :index, :show and :destroy actions before_filter PermissionCheck.new( :orders, :only => [:index, :show, :destroy] ) end.

Rails 4.0 and Devise With Strong Params and Custom Fields - GoRails. This post was written by Chris Oliver on August 18, 2013.

Rails 4.0 and Devise With Strong Params and Custom Fields - GoRails

As we all begin transitioning to Rails 4.0 and strong_params there are going to be a fair amount of changes to our gems and other integrations. Since the attr_accessible functionality no longer exists inside our models, we need to move this into the controllers that are responding to our web forms. Devise, one of the common authentication gems, provides a reasonably easy way to accept extra fields as part of registration. The first thing we do is add the extra fields to the model in the database. Adding custom fields to your Devise User model in Rails 4.

The Elements of Style in Ruby #2: Favor sprintf(format) over String#% Today’s topic is the following rule from the Ruby Style Guide: Favor the use of sprintf and its alias format over the fairly cryptic String#% method.

The Elements of Style in Ruby #2: Favor sprintf(format) over String#%

Kernel#sprintf and String#% basically do the same thing – the main difference is that sprintf is generally used as a command(it does not operate on its receiver) and String#% is obviously an instance method of the class String. Here’s the two of them in action: So, considering they both do the same thing why should you opt to use sprintf instead of %? Procs, blocks and anonymous functions (August Lilleaas' blog) Published November 08, 2008 This is a Big Picture™ post.

Procs, blocks and anonymous functions (August Lilleaas' blog)

I will attempt to give you a thorough understanding of how blocks and procs works in Ruby by showing examples and explaining basics. I will also show some examples from other languages, namely Javascript and Lua, in order to really expand on the Big Picture™ in this article. Storing pieces of code. Clone your Octopress to blog from two places - ZeroSharp. This post covers how recreate a local repository of your Octopress blog.

Clone your Octopress to blog from two places - ZeroSharp

Perhaps you’ve accidentally lost it, or perhaps you would like to be able to blog from two different places. Recently I bought a new computer and I wanted to be able to blog from both my desktop and my laptop. How Octopress works Octopress repositories have two branches, source and master. The source branch contains the files that are used to generate the blog and the master contains the blog itself. When the local folders are initially configured according to the Octopress Setup Guide, the master branch is stored in a subfolder named ‘_deploy’.

To recreate the local directory structure of an existing Octopress blog, follow these instructions. Clone your blog to the new machine. Preload, Eagerload, Includes and Joins - BigBinary Blog. Rails provides four different ways to load association data.

Preload, Eagerload, Includes and Joins - BigBinary Blog

In this blog we are going to look at each of those. Preload Preload loads the association data in a separate query. Includes Vs Joins in Rails - Nikhil Lingutla. Let us understand the difference between includes() method and joins() method provided by ActiveRecord query interface in Rails framework Let us assume an User and a Post model Now, in Posts Index page, we want to display all the posts along with the associated User name. We can do that in one of the following two ways First Approach. Bundler. One thing we hear a lot by people who start to use bundler is that the workflow is more complicated than it used to be when they first start.

Bundler

Here’s one (anonymized) example: “Trying out Bundler to package my gems. Still of the opinion its over-complicating a relatively simple concept, I just want to install gems.” Tearing Down Capybara Tests of AJAX Pages » Salsify. At Salsify we write lots of Capybara integration tests of our single-page app.

Tearing Down Capybara Tests of AJAX Pages » Salsify

These tests are a key part of the infrastructure that allow us to move fast and refactor without break anything. Unfortunately as we added more and more tests we started experiencing sporadic hangs and database deadlocks while tearing down tests. After some investigation we figured out the problem was our JavaScript client making AJAX requests to our Rails server during the test teardown process.

Paypal Express Checkout with Ruby on Rails and paypal-sdk-merchant. In my last work, Agrimè.it, an ecommerce built using Ruby on rails, I had to implement the cart payment using Paypal Express Checkout. Sadly, I found that was the worst time to do it, because Paypal was migrating the classic API to the new REST API and the documentation was a real mess! Walking through the doc links, I jumped (without a particular logic) from the new to the old API reference and vice versa.

After a long work, me and Alessandro were able to create a working Ruby class to implement Express Checkout using the classi API and the paypal-sdk-merchant gem. If you want to try the new REST API check this link and use the paypal-sdk-rest gem. If you succeed in using it, please let me know or write something about it.

For non-US developers: before using the new REST API check if they work in your country. 7 daily use cases of Ruby Hash. Step-by-Step Guide to Building Your First Ruby Gem - Quick Left Boulder Colorado. Building your first Ruby gem may seem like a daunting task, but it's actually not so bad. It's quite rewarding to not only release a gem, but to see its download count climb as others put your hard work to good use, and even still as others offer to contribute new features and bug fixes to your very own gem. And thanks to RubyGems.org and Bundler, the process of creating, releasing, and implementing gems couldn't be easier.

After reading through this post, get access to the 45 minute video tutorial complete with slide deck and instruction from Matt in our new Engineering Lunch series. Be a QLer for the day and see what we're teaching our engineers in our semi-monthly engineering lunch series. Sorry, we don't buy the lunch but you do get the tutorial for free! A gem is essentially a Ruby plugin. The concept of Ruby plugins actually predates the concept and implementation of Ruby gems. HubSpot/tether. Confident Ruby. Overwriting Console Output in Ruby. I've always liked the way some long running console utilities display their status without having to print a new line. For example the little spinner that alternates displaying |, /, and \. Or various internet utilities that display the percentage of the file that has been downloaded. Rails 3 Autoload Modules/Classes – 3 Easy Fixes. Judging by the number of queries on Stack Overflow, it is a very common problem for folks using Rails 3 that they are not getting the modules or classes from their lib directory loaded in Rails 3, especially in production.

#53 Handling Exceptions (revised) Daily Ruby Tip #32 – Simple Ruby Class for Sending SMS with Twilio. How to install Xcode, Homebrew, Git, RVM, Ruby & Rails on Snow Leopard, Lion, and Mountain Lion - Moncef Belyamani. This tutorial was last updated on March 3, 2015. NEW: My laptop script can automate the whole setup for you.

Tried several fixes: Heroku/Rails 4 Assets Precompile Error. Why-i-love-data. In a ruby script, there's a keyword __END__ that for a long time I thought just marked anything after it as a comment. Link_to_unless_current (ActionView. Objects on Rails. Storage. SEO and Obfuscating Database IDs in Ruby on Rails. Creating Vanity URLs in Rails. A vanity URL is a search engine optimized (SEO) URL.