Jump to content

The ultimate community for Ruby on Rails developers.


add custom commands available in rails console

  • Please log in to reply
1 reply to this topic

#1 ramborp



  • Members
  • 1 posts

Posted 07 February 2014 - 06:06 AM



I'd like to create some custom methods that are available through the rails console and was wondering how to go about that given the methods will be Model independent. I tried adding a function to ApplicationController but that did not work.  For instance, if I wanted to alias Dir.pwd as 'pwd' ,where would I add the method to interprete the syntax?


Thanks for you thoughts,



#2 Jamie



  • Moderators
  • 141 posts
  • LocationNewcastle, UK

Posted 07 February 2014 - 05:55 PM



Welcome to RailsForum.


I would encourage adding these methods to the model so they're available on a record or scope basis.




If you have a first_name and last_name row in your User table you could create a full_name method in your User.rb file which contains something like...

def full_name
    "#{first_name} #{last_name}"

Hopefully this makes sense! If you provide us with something you're trying to create from your code we'll be able to help you more!




Rails developer based in Newcastle, UK.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users