Code Worrier

Teaching myself to RTFM

Quick Tip: Helper Methods in the Rails Console?

| Comments

So you want to mess around with a helper method in the console? It’s super simple, as I just learned here from kch. Basically, Rails gets a bit yo dawg and provides a helper for your helpers—called “helper”.

Here’s an example. Suppose you have a helper module like the following:

cars_helper.rb
1
2
3
4
5
6
7
8
9
module CarsHelper

  def put_a_car_in(location)
    if location == "your car"
      puts "So you can drive while you drive!"
    end
  end

end

Fire up a Rails console, and to create the helper-helper, all you have to do in include the module:

1
2
3
4
5
>> include CarsHelper
=> Object

>> helper.put_a_car_in("your car")
So you can drive while you drive!

I hope this has been helpful. (Sorry, can’t help myself.)

Ok, I’m done.

Comments