Rails Console Challenge

Collapse Content

Can you create a very simple version of the Rails Console? This challenge is similar to the program built in Ruby for Rails, but it just involves building a console (there's no controller involved).

You should create a class Post to run the program. The input will consist of commands for your program to execute on the class Post.

You will be given input on Standard Input, which your program needs to read in. Each line of input will contain a command for your program to perform on the class Post. Here are the three possible actions that will come in as input, along with the action your program should take:

  • Post.create(content) - Creates a post with given content.
  • Post.find(id) - Returns a post with a given id.
  • Post.last - Returns the last-created post.

When a post is printed (e.g. with puts), it should just prints its content. The program should quit when given the input quit.

ID's - The ID for a post should be assigned in order of when the post is created. The first post created should have an ID of 1, the second an ID of 2, etc.

Sample Input/Output

sample input sample output action taken
Post created
(Creates and saves post.)
puts Post.find(1)
Returns first post (i.e. with ID of 1) and prints its content.
puts Post.last
Returns last created post and prints its content.


Create a simple Rails console as specified.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


  • What are we assumed to have available? If there's a Rails project, the console already exists and using get and eval is unnecessary. If not, are we supposed to re-implement all of ActiveRecord

  • You just need to handle the input and output described. This isn't really Rails; the idea is to build a simple program inspired by the Rails console. The actual contest challenges ask to build some additional functionality.

Contact Us
Sign in or email us at [email protected]