Welcome To Snipplr


Everyone's Recent Rails Snippets



Можно выкладывать даже файлы, содержащие кириллицу в названии. Они будет подвергнуты транслитерации, пробелы и другие небезопасные симÐ...
0 1669 posted 16 years ago by almazom
0 1474 posted 16 years ago by almazom
creates something like list_49 with the 49 corresponding to id of record in database.
0 1363 posted 16 years ago by deschism
0 1343 posted 16 years ago by almazom
Put the following in your controller to define the content-type for *that* specific controller.
0 1237 posted 16 years ago by chrisamini
count(*args) Count operates using three different approaches. Count all: By not passing any parameters to count, it will return a count of all the rows for the model. Count using column: By passing a column name to count, it will return a count of...
1 1558 posted 16 years ago by deschism
The 'request' and 'response' objects are chock full of useful info. But console can't usually access them. Here's how: start the server with the -u option, insert a breakpoint where you would like to have access to the controllers/helpers/etc. Wh...
1 1888 posted 17 years ago by cczona
Can be used to generate a random code for an online voucher. You just need to set VOUCHER_CODE_LENGTH in your environment.rb or similar.
1 1540 posted 17 years ago by jordanbrock
2 1600 posted 17 years ago by nhutto
Instead of simply adding a list of things at the end of the array, you can also pass in a hash and change the question marks to actual named replacements. This can help you keep the order of your arguments straight.
1 1523 posted 17 years ago by sohooo
0 1392 posted 17 years ago by oli
3 1657 posted 17 years ago by oli
Install an older version of a gem.
1 1501 posted 17 years ago by twofivethreetwo
Populate your states table with US States. Easy rake task for it.
2 1753 posted 17 years ago by twofivethreetwo
1 1441 posted 17 years ago by batamire
1 1092 posted 17 years ago by filiptepper
1 1715 posted 17 years ago by tonic
2 1352 posted 17 years ago by tonic
I normally paste this into config/mongrel.rb, then add "require 'mongrel'" in my config/deploy.rb Once that's done, you'll be able to start, stop, and restart your mongrels like so: `cap deploy:mongrel:start/stop/restart`
3 1667 posted 17 years ago by jimmyebaker
Send file from different name
1 1480 posted 17 years ago by tonic
2 2076 posted 17 years ago by tonic
1 1681 posted 17 years ago by mikegreen
"The new naming scheme for template (eg. .html.erb) does not seem to work for partials. When using :partial => 'form' a filename "_form.html.erb" is not recognized. " Rails now requires the partial to be referenced by dotted format
1 1440 posted 17 years ago by cczona
1 1625 posted 18 years ago by udayrayala