Welcome To Snipplr


Everyone's Recent Rails Snippets



0 386 posted 12 years ago by inkdeep
0 324 posted 12 years ago by nflamel
Create config/initializers/paperclip.rb
0 426 posted 12 years ago by Nek
0 399 posted 12 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 468 posted 12 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 370 posted 12 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 502 posted 12 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 524 posted 12 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 506 posted 12 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 390 posted 12 years ago by sgtrock
Regular menu item adding current class if current url equal menu item destination.
1 530 posted 12 years ago by smoothdzion
I needed to make menu items that kept the current class based on the controller being accessed.
1 394 posted 12 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 446 posted 12 years ago by smoothdzion
0 325 posted 12 years ago by obi
0 344 posted 13 years ago by jommy
The code to find all objects from a model and use them as select options.
1 440 posted 13 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 377 posted 13 years ago by smoothdzion
Used to create checkboxes to select multiple categories for a post or any other type of applicable situation.
1 385 posted 13 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 478 posted 13 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 484 posted 13 years ago by nate63179
In this instance, used as an after-deploy hook to create a symlink to a shared db config file
0 471 posted 13 years ago by nate63179