In a Rails application, *_spec.rb files get special treatment depending on the file's directory. E.g. when you put a...

makandra dev

When a Rails controller action should handle both HTML and JSON responses, do not use request.xhr? to decide that. Use...

blog.plataformatec.com.br

It is common in Rails 3.0 applications that you want to provide default views for a group of controllers. Let...

to create a Gallery that has a name and has_many :images, which in turn have a...

Simple: Tell the application controller how to handle exceptions, here a RecordNotFound error. Do this with the following line: # application_controller.rb...

railway.at

Note: These instructions are for a quick per-project setup and may require you to change code. If you generally...

Expiration of Rails sessions By default Rails sessions expire when the user closes her browser window. To change this edit...

makandra dev
github.com

Geoffrey Grosenbach has created Gruff for easily plotting graphs. It is written in pure Ruby and integrates with Rails applications...

The User-Agent HTTP header identifies the client and is sent by "regular" browsers, search engine crawlers, or other web...

makandra dev

Angular's directives have a transclude option, that allows for rendering an element's original content within the directive's...

You will need to upgrade to RSpec >= 2 and rspec-rails >= 2 for Rails 3. Here are some hints to...

Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the...

makandra dev

If you use a form (or form fields) multiple times inside one view, Rails will generate the same id attributes...

...ResourceController - here you have to be careful class PostController include ResourceController::Controller does 'post_controller/behavior' index.before { do_something } end module PostController::BehaviorTrait as_trait do index.before { do_something_else }

...Images are (usually) served directly from public or assets and won't hit your controllers/routes, as long as the files exist. If files are missing, the request will be handled...

Controller responses often include Javascript code that contains values from Ruby variables. E.g. you want to call a Javascript function...

github.com

paper_trail is an excellent gem to track record versions and changes. You almost never want to reimplement something like...

This trick might be useful to implement more complicated directives in AngularJS. I needed it to do drag'n'drop...

When your Rails controller action responds with only a simple text, render text: 'Hello' may not be what you want...

The cookies object in your controllers and views is a ActionController::CookieJar and even though that class inherits from Hash...

Just assign the existing attachment to another record: new_photo = Photo.new new_photo.image = old_photo.image Paperclip will duplicate the file when saving...

If you want to inspect the compiled code of your erb (or haml) templates, you can run the following code...

Selenium does not speak SSL because it uses WEBrick that doesn't. When you use Selenium for Cucumber scenarios that...

blog.codeclimate.com

“Fat models” cause maintenance issues in large apps. Only incrementally better than cluttering controllers with domain logic, they usually represent...