Home


Welcome to RailsRocket, a community Ruby on Rails website! We have forums, so check those too; we hope this will help you with your Ruby on Rails projects!

Newest Articles

  • Rails 2.1: The First and the Last [August 26, 2008]: Rails always made it easy to grab the first item in any ActiveRecord model. Rails 2.1 allows you to easily grab the last element, too, with the syntax ActiveRecord.find(:last). Like :first, you can add limits, conditions, etc. to it. Additionally, there are new static methods to allow you to call ActiveRecord.first and ActiveRecord.last to get
  • Exception and Error Handling [August 23, 2008]: A lot of programming languages have an error-catching (or exception-handling) mechanism, where you can trap errors. How do we do this in Ruby? There are two keywords: begin, and rescue; and the ancestor of all errors is called StandardError.
  • Ruby Interactive Prompt [August 20, 2008]: The great “try ruby!” online interactive prompt is broken! How can we write some code that runs almost the same, albeit in a local Ruby environment? A few minutes of experimentation revealed this little snippet, which works fairly well.
  • Functions as First-Class Objects [August 17, 2008]: A lot of programming languages have functions as first-class objects (you can pass them around, execute them, etc.) Ruby has some sort of functionality like that (proc and functors and yield, oh my!), but there’s a simpler solution: the (albeit abusable) eval method.
  • Drilling Down into Validation Failure [August 8, 2008]: Rails provides model-level validation, which is easy and DRY. But if you have a class that validates multiple fields, how can you verify if validation is failing on the right fields? ActiveRecord provides a convenient errors method with an invalid? method you can call; it takes a field name.
  • Many-to-Many Association [August 6, 2008]: How can you create a many-to-many association in Rails? We discuss two approaches. The first approach uses a join table with a composite primary key, and nothing else; Rails does the heavy lifting. The second approach is through an intermediary class that contains additional data about the relationship of the two elements in the many-to-many
  • Page Rendering Time [August 5, 2008]: A lot of websites show the page rendering time at the bottom. How can we implement this in our Rails website? We discuss a simple approach, where you wrap between two calls to Time.now (to get the current time). Subtracting them yields the time difference, in fractional seconds.
  • Singleton Classes [August 1, 2008]: How can you create a singleton class in a Rails application? The same as in a Ruby application! Using Singleton gives you free functionality: it makes the constructor private, and it creates a static method called instance, to get the singleton instance. If you check equality for two singleton instances, they will always be equal.
  • Passing Controller/View Data with Instance Variables [July 29, 2008]: In Rails, instance variables are preceded by the @ symbol. Instance variables in controllers are automatically accessible in view pages. In this way, Rails ties together the model, view, and controller aspects. The result is that you access model data and store it in instance variables in your controller, then display it through using those
  • MySQL Configuration for Rails [July 26, 2008]: As of Rails 2.0, the helper to generate a new application structure uses SQLite instead of MySQL. While MySQL is more heavyweight, it has some strengths over SQLite, such as power GUI tools, and the ability to rename columns. If you need a MySQL database configuration sample, we have one here!

Most Popular

  • Migrating to Rails 2.0
  • Passing Controller/View Data with Instance Variables
  • Rails 2.1 eBook
  • Foxy Fixtures Explained
  • Find_by_SQL
  • Extending Acts_as_Authenticated
  • Scaffolding in Rails 2.0
  • MySQL Configuration for Rails
  • Migrations
  • Routing in Rails

  • Highest Rated

      Posted in Uncategorized

    Leave a Reply