the interactive, command-line interface to the Ruby-based Rails framework. The Rails console allows developers to interact directly with their application without using a browser.
Questions tagged [rails-console]
441 questions
10
votes
2 answers
How can I print each element of an array on its own line in the Rails console?
When I run the Rails console, how can I display each item on its own line? Instead of
> Post.all
=> #

Chloe
- 25,162
- 40
- 190
- 357
10
votes
4 answers
Delete all in rails console
i have an association for a user as user has_many agents and agent belongs_to user.
in rails console,i am trying to use different users to test a particular scenario and i want a user with no agents,hence i want to delete the user.agents.
i tried…
user2164011
9
votes
1 answer
Rails console won't load environment variables in secrets.yml
I am trying to debug a problem with secrets.yml loading environment variables, by setting some environment variables in development and running rails c to inspect things. When I load Rails.applications.secrets this way, it is not picking up any of…

mltsy
- 6,598
- 3
- 38
- 51
9
votes
1 answer
What do the colors of output in rails console and Rails server log mean?
I'm running rails server and rails console in Ubuntu 14.04 inside the generic terminal (app is just called "Terminal").
Whenever I run commands that involve the database, the console outputs which SQL query it sent but sometimes the text a turquoise…

StephanieS
- 423
- 4
- 12
8
votes
1 answer
how can I run an initializer from the rails console?
I've got an initialization file config/initializers/linkedin.rb that sets up the Linkedin gem so that my app can connect to the LinkedIn service and run queries. I'm now testing out some new features and I want to use the console for this. My…

spinlock
- 3,737
- 4
- 35
- 46
8
votes
2 answers
How to run code automatically when launching a Rails console?
Let's say I wanted a greeting every time the Rails console comes up:
Scotts-MBP-4:ucode scott$ rails c
Loading development environment (Rails 4.2.1)
Hello there! I'm a custom greeting
2.1.5 :001 >
Where would I put the puts 'Hello there! I\'m a…

at.
- 50,922
- 104
- 292
- 461
8
votes
3 answers
Rails does not permit changing locale
I'm trying to change the locale that my rails (4.1.4) application is using, but every time I try to change it in the console using commands such as
I18n.locale = :es
I18n.default_locale = :de
an I18n::InvalidLocale error is brought up. This is the…

Anrothan
- 500
- 5
- 13
8
votes
1 answer
Rails cache from the console returning nothing nil
I am unable to see anything in the cache from the console in either development or production.
For development, I have turned on caching and set it to memory store, in production I use the dalli gem and Memcachier on Heroku.
Every key I try comes…

Hsiu Dai
- 1,303
- 2
- 14
- 21
8
votes
4 answers
Is there a way in the Rails Console to print a table of database contents?
I'm looking for a clean and simple way to print in the Rails Console the contents of my 5 row database with 2 columns.
Any ideas? I Googled around but didn't find much.

Zack Shapiro
- 6,648
- 17
- 83
- 151
7
votes
2 answers
List all Mongoid models in Rails console
I want to list all the models which have a respective collection in my mongodb database? I'm using mongoid gem for for MongoDB.
I would try something like this
ActiveRecord::Base.send :subclasses
which works fine, but I'm not using ActiveRecord.

Kumar
- 3,116
- 2
- 16
- 24
7
votes
6 answers
Add tests for dependent :destroy in the Relationship model (Chapter 11, Exercise 1 Rails Tutorial, 2nd Ed)
Pretty sure these tests are working correctly. Got them to fail by removing the dependent: :destroy options on the has_many :relationships and has_many :reverse_relationships in user.rb.
Wanted to share what I did in case anyone else is working…

Brett Sanders
- 813
- 8
- 21
6
votes
1 answer
Object doesn't support #inspect
Getting an issue when running simple tasks in the ruby console.
If I run
user = User.find(10)
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", "10"], ["LIMIT", 1]]
(Object doesn't support #inspect)
I get…

bubbaspaarx
- 616
- 4
- 15
6
votes
2 answers
Why is my params hash nil?
In my rails controller, in a pry session, my params hash is nil. request.params has the expected hash.
If I comment out the params = … line, params returns to normal.
class UsersController < Clearance::UsersController
skip_before_filter…

John Bachir
- 22,495
- 29
- 154
- 227
6
votes
1 answer
Disable stack trace display in Rails console
Is there any way to reduce the verbosity of error reporting in the rails console? Specifically, turn off the stack trace display? It's of no use most of the time, and downright annoying when I'm suffering from a case of the stupid fingers.
When I…

Ian
- 602
- 8
- 12
6
votes
4 answers
Can't run rails c in terminal because of "Pry failed to get user input using `Readline`."
I can't seem to run rails c in terminal.
It keeps giving me this error
Loading development environment (Rails 4.2.0.beta2)
[1] pry(main)> Error: Input/output error - /dev/null
/Users/Bito/.gem/ruby/2.0.0/gems/pry-0.10.1/lib/pry/repl.rb:198:in…

Louis Hoang
- 61
- 3