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 593 posted 17 years ago by Agent
1 965 posted 17 years ago by jpowell
1 659 posted 17 years ago by jpowell
1 583 posted 17 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 779 posted 17 years ago by vanne
Put this in environment.rb to use in your whole app or the console
1 788 posted 17 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 754 posted 17 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 856 posted 17 years ago by wackimonki
This will add up all the prices and return it? What does |item| mean exactly?
2 718 posted 17 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 802 posted 17 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 689 posted 17 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 712 posted 17 years ago by wackimonki
Add this inside your .irbrc file to call "show Model" in your console instead of "y Model.column_names"
1 732 posted 17 years ago by vanne
Displays a image inside link_to instead of text.
2 849 posted 17 years ago by ryanprel
Add this to your ~/.irbrc file and you will have inline logging in the console
1 708 posted 17 years ago by vanne
Use this to sanitize a string and convert all wierd characters to your choice of delimiter
1 826 posted 17 years ago by vanne
Define multiple associations on the same associated class. From the Rails Way blog.
1 618 posted 17 years ago by gnatware
3 978 posted 17 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 665 posted 17 years ago by andyh
put this into lib/tasks and then run rake db:version
1 680 posted 17 years ago by vanne
Useful for when you need to do a find and map specific results to an array for use later
1 781 posted 17 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 1217 posted 17 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 1013 posted 17 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 1671 posted 17 years ago by tjstankus
Rails builds on the standard Ruby observer, so you can too. Originally found at http://rails.techno-weenie.net/forums/1/topics/672?page=6, so don't give me any credit ;)
2 690 posted 18 years ago by stuckinrealtime