Questions tagged [rails-console]

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.

441 questions
17
votes
4 answers

How can I run an ActiveJob in Rails console for debugging?

I currently have an ActiveJob that I've created and use Sidekiq to queue it. I'm wanting to debug the job, but for me to see any messages I program into it I have to check my log files. I feel like it would be more convenient to be able to see my…
daveomcd
  • 6,367
  • 14
  • 83
  • 137
15
votes
5 answers

rails c not working in rails 5

On using the command in terminal inside a rails 5 application rails c the error thrown is given bellow. I have no idea what this means in a similar question here that for which the solution was to use spring stop. I have tried that too but no it…
15
votes
1 answer

prettify JSON output of active-model-serializer in rails console

I am testing active-model-serializer output in the rails console and I am looking for a way to prettify the output. The the only solution I have found so far is: ap JSON.parse(ProfileSerializer.new(p).to_json) That seems like a roundabout approach.…
errata
  • 23,596
  • 2
  • 22
  • 32
14
votes
1 answer

Rails 3 Sandbox Console

In Rails 2 you're able to run script/console --sandbox so you can play with production data and not accidentally break anything. I can't seem to find the equivalent command for Rails 3. Does anyone know what it is?
Ganesh Shankar
  • 4,826
  • 8
  • 43
  • 56
14
votes
2 answers

How can I run rails console in Heroku? Rails 5.1 and postgresql

I've been following along with a tutorial for a Rails app. The tutorial is based on Rails 5 and I am using Rails 5.1.2. Everything works great locally and pushed to heroku with no problems. However, when I went to create an admin user on the…
Luke Popwell
  • 381
  • 1
  • 3
  • 15
14
votes
2 answers

Rails console 'y' helper returns NameError rather than yaml-formatting output

I'm trying to use y object in Rails 3.2.6/Ruby 1.9.3 console to get nicely formatted yaml output for an ActiveRecord object, but for some reason it isn't working for me. I've used it in the past, but somewhere along the way it broke. I get the…
13
votes
2 answers

Rails console (END) how to get past it?

working in the Rails console, I pasted a very long hash into the console and when I scrolled ot the bottom of it it has the token (END) but the only way I've found to get past it is to exit the console with CTRL+Z. This defeats my purpose in using…
Paul
  • 35,689
  • 11
  • 93
  • 122
12
votes
3 answers

How to attach the Rubymine IDE debugger to a shell process?

I want to use Rubymine's IDE debugger to debug a ruby process running in the command shell, as it is spawned, e.g. by "rails console". I've gotten great mileage out of the debugger when running the web server (from within Rubymine) or test suites…
Wolfram Arnold
  • 7,159
  • 5
  • 44
  • 64
12
votes
2 answers

Run script in Rails console and have access to objects created?

I recently found you can run an arbitrary Ruby file in the Rails console using load or require, as in: load 'test_code.rb' This is great as far as it goes, but using either load or require (what's the difference?) I don't seem to have access to the…
Dan Barron
  • 1,094
  • 2
  • 15
  • 30
12
votes
2 answers

What is wrong with readline?

I set up a Rails environment three times with different OSes and with Rails 3 and 4. It goes smoothly until I open a console to type some Ruby, or inspect my database with rails console or rails dbconsole. I get something similar to: $ rails…
toftis
  • 1,070
  • 9
  • 26
12
votes
2 answers

Enable stack dump on exception in Rails console

I am using Ruby on Rails with the pry gem. When an error occurs during a rake task, I get a very nice stack trace. When however I do something in my rails console that triggers an exception, I only get to see the error message and the one line of…
Pelle
  • 6,423
  • 4
  • 33
  • 50
11
votes
2 answers

Using asset_path in Rails console

In my Character model I have added: character.rb before_save do self.profile_picture_url = asset_path('icon.png') end However, for all the Characters that already exist in the database, their profile_picture_url is nil. I therefore want to enter…
Bazley
  • 2,699
  • 5
  • 36
  • 61
11
votes
1 answer

Easy way to suppress SQL output in Rails console?

I frequently need to go on the Rails console with rails c. Then I run some statement which loops through records of a model. I need to output information, but all the SQL code gets littered throughout as well. Like: Students.all.each {|s| puts…
at.
  • 50,922
  • 104
  • 292
  • 461
11
votes
2 answers

Rails console issues using JRuby: no prompt character, no tab completion, broken arrow keys, etc

I'm having various issues with my Rails console under JRuby, including No prompt character Tab completion not working (literal tab gets inserted) Up/down arrows not browsing history (^[[A or ^[[B gets inserted, respectively) Left/right arrows not…
Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
10
votes
5 answers

~/.irbrc not executed when starting irb or script/console

Here's what I've tried: 1. gem install awesome_print 2. echo "require 'ap'" >> ~/.irbrc 3. chmod u+x ~/.irbrc 4. script/console 5. ap { :test => 'value' } Result: NameError: undefined local variable or method `ap' for #
Patrick Klingemann
  • 8,884
  • 4
  • 44
  • 51
1
2
3
29 30