RubyOnRails

What is RoR?

RubyOnRails, aka RoR or rails, is a web development framework written in Ruby.

Why RoR?

It's awesome. :)

Installing RoR

Resources

Tips & Tricks & Other Useful Stuff

  • Sometimes you want to output to console for some quick debugging (often to see whether the code reaches a certain point), try using puts “Output to Console Now!”
  • When scaffolding, make sure that you enter a non-plural version of the table name (eg. script/generate scaffold group name:string not script/generate scaffold groups name:string). Rails will automatically pluralize the word for you when you scaffold. Otherwise, the result is a NameError in ######Controller with a message such as uninitialized constant ######Controller::###### (where ###### is the controller's name).
  • If you want to check if a variable is empty or nil (or both), use .blank?. It will properly perform the check regardless of what type it is.
  • When dealing with has_many, belongs_to, etc. relationships, use rails built in associations to access objects whenever possible. For example, if a Book has many Pages, and you want to find a particular Page of the Book, use @book.pages.find(params[:id]) rather than Pages.find(params[:id]). This helps to ensure that the specific page belongs to the book making everything more secure. When creating a new page for a specific book, try @book.pages.new(params[:page]). This automatically associates the page with the book so you do not need to edit page.book_id. The find and new methods behave exactly the same as the ActiveRecord's find and new methods (they can accept more than just the params[] that were used in the example). Other things to note, @page.book returns the book object the page belongs to. @book.pages returns a collection of all pages belonging to it. These associations will make the code cleaner and save time.
 
ref/backend/rubyonrails.txt · Last modified: 2009/12/09 14:23 by rafd
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki