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 81 posted 10 years ago by chrisaiv
0 72 posted 10 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 168 posted 10 years ago by chrisaiv
0 80 posted 10 years ago by almazom
0 80 posted 10 years ago by inkdeep
0 75 posted 10 years ago by nflamel
Create config/initializers/paperclip.rb
0 116 posted 10 years ago by Nek
0 76 posted 10 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 127 posted 10 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 85 posted 10 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 113 posted 10 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 137 posted 10 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 129 posted 10 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 83 posted 10 years ago by sgtrock
Regular menu item adding current class if current url equal menu item destination.
1 111 posted 10 years ago by smoothdzion
I needed to make menu items that kept the current class based on the controller being accessed.
1 81 posted 10 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 118 posted 10 years ago by smoothdzion
0 68 posted 10 years ago by obi
0 75 posted 10 years ago by jommy
The code to find all objects from a model and use them as select options.
1 87 posted 10 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 81 posted 10 years ago by smoothdzion
Used to create checkboxes to select multiple categories for a post or any other type of applicable situation.
1 89 posted 10 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 107 posted 10 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 104 posted 10 years ago by nate63179