Welcome To Snipplr
Everyone's Recent Ruby Snippets Tagged rails
- All /
- JavaScript /
- HTML /
- PHP /
- CSS /
- Ruby /
- Objective C
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
700
posted 17 years ago by Agent
This is an easy to use any helpers that rails provides in any other place besides views and view helpers
1
879
posted 17 years ago by vanne
Put this in environment.rb to use in your whole app or the console
1
877
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
831
posted 18 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
973
posted 18 years ago by wackimonki
This will add up all the prices and return it?
What does |item| mean exactly?
2
810
posted 18 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
888
posted 18 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
774
posted 18 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
819
posted 18 years ago by wackimonki
Add this inside your .irbrc file to call "show Model" in your console instead of "y Model.column_names"
1
847
posted 18 years ago by vanne
Add this to your ~/.irbrc file and you will have inline logging in the console
1
803
posted 18 years ago by vanne
Use this to sanitize a string and convert all wierd characters to your choice of delimiter
1
911
posted 18 years ago by vanne
Define multiple associations on the same associated class. From the Rails Way blog.
1
702
posted 18 years ago by gnatware
used to remove unnecessary duplication of code. Code is from Jamis Buck (http://weblog.jamisbuck.org/2007/1/24/object-with_options)
1
770
posted 18 years ago by andyh
Useful for when you need to do a find and map specific results to an array for use later
1
877
posted 18 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
1336
posted 18 years ago by vanne
This allows you to turn off ajax requests application wide, so that you don't have to do render :layout => false in every controller that needs it.
1
1111
posted 18 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
1803
posted 18 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
776
posted 18 years ago by stuckinrealtime