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
442
posted 16 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
595
posted 17 years ago by vanne
Put this in environment.rb to use in your whole app or the console
1
634
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
575
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
663
posted 17 years ago by wackimonki
This will add up all the prices and return it?
What does |item| mean exactly?
2
571
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
621
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
542
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
547
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
559
posted 17 years ago by vanne
Add this to your ~/.irbrc file and you will have inline logging in the console
1
555
posted 17 years ago by vanne
Use this to sanitize a string and convert all wierd characters to your choice of delimiter
1
666
posted 17 years ago by vanne
Define multiple associations on the same associated class. From the Rails Way blog.
1
471
posted 17 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
489
posted 17 years ago by andyh
Useful for when you need to do a find and map specific results to an array for use later
1
618
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
964
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 => false in every controller that needs it.
1
821
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
1369
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
519
posted 17 years ago by stuckinrealtime