Perforce corrupts Scripts

On windows, I am mapping a linux drive. So in Perforce, when I do a perforce sync, the files on linux will get updated. After doing this, vs doing a perforce sync on the command line on Linux itself, I noticed that the script/server and script/generate commands didn’t work without typing “ruby ” in front [...]

auto_complete Plugin and Virtual Attributes

The way you normally specify which fields in your form should auto complete, is to add a declaration within your controller that looks like: auto_complete_for :model_name, :field_name However, this only works for actual fields that exist in your database, not for virtual attributes. So :field_name cannot be a virtual attribute, but should be a real [...]

Debugging Routes

ruby script/console To see how an external request would map to your internal path: >>rs = ActionController::Routing::Routes Sample: >>rs.recognize_path "/controller/action/id", :method => :get To reload routes.rb if you made changes to it: ActionController::Routing::Routes.reload —- To generate a path use generate method: >>rs.generate :controller => "controllername", :action => "actionname", :id => 123, :extra => "extrastuff" => [...]

Wym_Editor (WYSIWYM) Plugin for Rails

The wym_editor (WYSIWYM – “What you see is what you mean”) plugin is pretty cool. It allows you to define which form fields you want to offer WYSIWYM editing functionality. This makes it easier for you to edit fields and give them styles. It also allows you to see the HTML source view while you [...]

SET data type in MySQL and ActiveRecord

I figured out something cool which solves a common database design problem. However, I’m not sure if this is supported in ActiveRecord since the SET data type does not exist in all databases. Let’s say each record in a table has zero or more properties and your set of properties is pre-defined. How would you [...]

Dealing with Money in Rails

In process of determining how to handle fields such as price, in Rails, I’ve conducted some research. There seems to be a debate on whether to use decimal or integer as the price field. In case of where integer data types are used, the integer actually will store the price in cents. One argument for [...]

RVM and Frozen Rails Conflict

I have an existing rails application and want to switch to using RVM in order to tie particular versions of Ruby, Rails and RubyGems to this application. My existing Rails application has a frozen Rails version 2.2.2 tied into it and so exists in my vendor/rails directory. Before I installed RVM, the following question came [...]

Multiline Comments in Rails ERB Views

If you want to add multiline comments to your Rails .html.erb Views do the following. The =begin and =end need to be at the beginning of the lines for it to work! Also, you cannot have any ERB code in the =begin and =end blocks, if you comment this way. <% =begin This is a [...]

Ruby File Path Separators

File path separators on Unix systems and Windows are different. On Unix, a forward slash / is used and on Windows a backslash \ is used. However, when writing Ruby code you don’t need to worry about this; Just use the forward slash / character and it will be cross-platform for you. An even better [...]

Instance and Class Variable Accessor Methods

When you define classes in Ruby, you must specify what kind of access you want to give Instance and Class attributes/variables which are defined in that class. The way you do it is that you write reader and writer methods. You can write these methods out explicitly or use the shorthand attribute (attr_) methods like [...]