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 448 posted 16 years ago by Agent
1 772 posted 16 years ago by jpowell
1 493 posted 16 years ago by jpowell
1 438 posted 16 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 605 posted 17 years ago by vanne
Put this in environment.rb to use in your whole app or the console
1 644 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 587 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 673 posted 17 years ago by wackimonki
This will add up all the prices and return it? What does |item| mean exactly?
2 579 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 634 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 549 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 554 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 569 posted 17 years ago by vanne
Displays a image inside link_to instead of text.
2 669 posted 17 years ago by ryanprel
Add this to your ~/.irbrc file and you will have inline logging in the console
1 560 posted 17 years ago by vanne
Use this to sanitize a string and convert all wierd characters to your choice of delimiter
1 674 posted 17 years ago by vanne
Define multiple associations on the same associated class. From the Rails Way blog.
1 478 posted 17 years ago by gnatware
3 782 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 495 posted 17 years ago by andyh
put this into lib/tasks and then run rake db:version
1 526 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 624 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 976 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 830 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 1386 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 526 posted 17 years ago by stuckinrealtime