Welcome To Snipplr


Everyone's Recent Snippets Tagged rails



Add this to .irbrc. Allows the following in console: > gethtml('/login') => HTML of whatever page is generated by /login
0 3784 posted 15 years ago by insanedreamer
Just a funny, yet usefull fixture for testing users in a rails app. Using "somewhat real" fixtures, will keep testing both fun and realistic. Knowing that "Crabbe_ugly_nick" failed, is a lot easier to communicate then knowing "user_t_x01 failed"
0 1493 posted 15 years ago by berkes
in Rails 2, use `include ActionController::UrlWriter` instead.
1 3692 posted 15 years ago by insanedreamer
Put this in `test_helper.rb` and call with `show(object1, object2, etc.)`
0 3668 posted 15 years ago by insanedreamer
0 3394 posted 15 years ago by gmericksen
validate :price_must_be_at_least_a_cent protected def price_must_be_at_least_a_cent errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01 end
0 1450 posted 16 years ago by stayce
0 1404 posted 16 years ago by draq
0 1604 posted 16 years ago by deschism
0 1476 posted 16 years ago by inkdeep
0 1216 posted 16 years ago by nflamel
0 1414 posted 16 years ago by nflamel
1 1565 posted 16 years ago by wdso
0 1494 posted 16 years ago by almazom
0 1308 posted 16 years ago by kerpunk
1 1362 posted 16 years ago by wdso
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 1897 posted 16 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 1866 posted 16 years ago by nflamel
Easy way to add belongs_to association to nested forms in Rails
0 1782 posted 16 years ago by viatropos
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 2007 posted 16 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 1935 posted 16 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 1526 posted 16 years ago by sgtrock
Regular menu item adding current class if current url equal menu item destination.
1 1828 posted 16 years ago by smoothdzion
I needed to make menu items that kept the current class based on the controller being accessed.
1 1563 posted 16 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 1625 posted 16 years ago by smoothdzion
0 1250 posted 16 years ago by obi
0 1051 posted 16 years ago by tenpaiyomi