Welcome To Snipplr


Everyone's Recent Rails Snippets



In an effort to stay DRY, here's a simple way to organize your main navigation.
0 245 posted 11 years ago by chrisaiv
0 233 posted 11 years ago by gmericksen
Use this as a way to detect iPhone users using Rails 2+. This should live in your /controllers/application_controller.rb (class ApplicationController < ActionController::Base). You also need to modify your mime type.
2 457 posted 11 years ago by chrisaiv
0 243 posted 11 years ago by almazom
0 268 posted 11 years ago by inkdeep
0 228 posted 11 years ago by nflamel
Create config/initializers/paperclip.rb
0 296 posted 11 years ago by Nek
0 262 posted 11 years ago by almazom
This lets you type Mandarin tones like a1, o2, e3, and so on instead of having to type the real pinyin. The tones are saved with the proper characters in the database.
0 328 posted 11 years ago by 67ideas
Put the height_options method into a helper file, and use it as the select collection for select or collection_select. It allows heights between 4 feet and 7 feet. To change these limits, change 48 and 84 to some other numbers.
0 253 posted 11 years ago by 67ideas
This is the code I use when I want to test a helper. It uses Factory Girl and Shoulda, but they're not needed to make it work.
0 334 posted 11 years ago by nflamel
I used to directly inject javascript and CSS into my HEAD elements just like you see in all of the tutorials online and in books. Recently I decided to try a different approach, and I feel this is more in keeping with the ruby and rails "declaration"...
0 349 posted 11 years ago by sgtrock
I used to directly inject javascript and CSS into my HEAD elements just like you see in all of the tutorials online and in books. Recently I decided to try a different approach, and I feel this is more in keeping with the ruby and rails "declaration"...
0 353 posted 11 years ago by sgtrock
I never can remember the exact name of the exception to call in self.down for a migration that cannot be undone. So I decided to come up with something easier to remember. This feels more "ruby-ish" and "rails-ish" to me, and so far it works just fin...
0 267 posted 11 years ago by sgtrock
Regular menu item adding current class if current url equal menu item destination.
1 349 posted 11 years ago by smoothdzion
I needed to make menu items that kept the current class based on the controller being accessed.
1 256 posted 11 years ago by smoothdzion
I needed to copy the value of one field to a couple of others in case users decided to forget to fill them out. Using jQuery and added it to a helper because I was using in multiple places. Created variables to make it more readable.
1 315 posted 11 years ago by smoothdzion
0 223 posted 11 years ago by obi
0 247 posted 11 years ago by jommy
The code to find all objects from a model and use them as select options.
1 290 posted 11 years ago by smoothdzion
For separating a list of categories with a comma that are linked. There may be a better way. Leave a comment if you have a better way. This was the first way I found that worked. This code increments the count 1 at a time. It applies the incre...
1 258 posted 11 years ago by smoothdzion
Used to create checkboxes to select multiple categories for a post or any other type of applicable situation.
1 271 posted 11 years ago by smoothdzion
requires Rails libraries. could be rewritten to just use core Ruby libs, but I'm too lazy right now and I use this entirely in my Rails apps.
0 308 posted 11 years ago by mepatterson
This could be further abstracted to work with other db's. Also, it really should be using Ruby's Tempfile class instead of assuming the local machine is *NIX based, but it works :)
0 300 posted 11 years ago by nate63179