Welcome To Snipplr


Everyone's Recent Ruby Snippets Tagged rails



This function (intended to be an application or view helper) creates a pager bar useful for navigating many pages. It shows the first, last, current, nearby, and halfway-to-end pages. It looks like this (where the current page is 11): < 1 ... 5 .....
1 67 posted 13 years ago by Agent
1 96 posted 13 years ago by jpowell
1 61 posted 13 years ago by jpowell
1 57 posted 13 years ago by greystate
This is an easy to use any helpers that rails provides in any other place besides views and view helpers
1 78 posted 13 years ago by vanne
Put this in environment.rb to use in your whole app or the console
1 90 posted 13 years ago by vanne
Renders the partial template called 'cart', sends along local variable @cart, this will be known locally using the same name as the partial, 'cart'.
1 76 posted 13 years ago by wackimonki
The code tests if session[:counter] exists. If you leave out the all important '?', it will fail with an error.
1 81 posted 13 years ago by wackimonki
This will add up all the prices and return it? What does |item| mean exactly?
2 74 posted 13 years ago by wackimonki
Redirects from one method to another in a controller. This is handy when there's an error, and you need to go back to index page, or for other purposes.
1 93 posted 13 years ago by wackimonki
Adds a button in view, which triggers a method. "Empty cart" is the button name empty_cart is the method name
1 80 posted 13 years ago by wackimonki
Catches an exception error, uses a technique called flash to display error on another page. The Ruby on Rails code needs to be in a controller. The rhtml code needs to be in the index layout.
1 72 posted 13 years ago by wackimonki
Add this inside your .irbrc file to call "show Model" in your console instead of "y Model.column_names"
1 90 posted 13 years ago by vanne
Displays a image inside link_to instead of text.
2 89 posted 13 years ago by ryanprel
Add this to your ~/.irbrc file and you will have inline logging in the console
1 81 posted 13 years ago by vanne
Use this to sanitize a string and convert all wierd characters to your choice of delimiter
1 76 posted 13 years ago by vanne
Define multiple associations on the same associated class. From the Rails Way blog.
1 53 posted 13 years ago by gnatware
3 98 posted 13 years ago by zuwiki
used to remove unnecessary duplication of code. Code is from Jamis Buck (http://weblog.jamisbuck.org/2007/1/24/object-with_options)
1 61 posted 13 years ago by andyh
put this into lib/tasks and then run rake db:version
1 86 posted 13 years ago by vanne
Useful for when you need to do a find and map specific results to an array for use later
1 109 posted 13 years ago by vanne
This is useful for using ActiveRecord validations without the ActiveRecord DB dependencies, this snippet is meant to be used with Textmate... create this in models/name_of_your_model to use.
4 131 posted 13 years ago by vanne
This allows you to turn off ajax requests application wide, so that you don't have to do render :layout =&gt; false in every controller that needs it.
1 138 posted 13 years ago by vanne
fixture_file_upload is another nifty Rails testing feature. It allows you to create "MIME-encoded content that would normally be uploaded by a browser input field." (Part in quotes straight from Agile Web Development with Rails, v2). Put your files t...
3 222 posted 13 years ago by tjstankus