rails-console

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

a 夏天 提交于 2019-12-04 02:31:00
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 moving cursor ( ^[[D or ^[[C gets inserted, respectively) Home / End keys not moving cursor to beginning/end of line (instead 1~ or 4~ inserted, respectively); Ctrl + a / Ctrl + e work though Ctrl + c killing console instead of killing the line I'm entering Ctrl + d not having any effect until I hit Enter (which then executes anything I entered

Rails 3 Sandbox Console

≡放荡痞女 提交于 2019-12-03 23:49:42
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? Easy, type in: bundle exec rails c -s and that is it. $ bundle exec rails c --help Usage: console [environment] [options] -s, --sandbox Rollback database modifications on exit. --debugger Enable ruby-debugging for the console. --irb DEPRECATED: Invoke `/your/choice/of/ruby script/rails console` instead It is simple, but, sometimes, if you are not running rails executable using

how can I run an initializer from the rails console?

爷,独闯天下 提交于 2019-12-03 12:49:39
问题 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 problem - asside from being a newb and not understanding the console very well yet - is that I can't access the variables that are initialized in config/initializers/linkedin.rb . Any ideas on how to use the application initializers from within the

Write to rails console

狂风中的少年 提交于 2019-12-03 06:12:02
问题 When I want to try or debug smthing I run rails console and do some stuff there. I can print some text or variables from code by raising exception with raise "blablabla" . Question: How I can just write to rails console without exception raising (and obvious breaking code execution) like a simple logger.info "blah" ? 回答1: As other have said, you want to use either puts or p . Why? Is that magic? Actually not. A rails console is, under the hood, an IRB, so all you can do in IRB you will be

Rails Console - Find where created at = certain day

与世无争的帅哥 提交于 2019-12-03 05:43:55
问题 With Ruby on Rails console, is it possible to query the database for all records created on a certain day? something like date = "january 5 2013" users = User.find(:all, :conditions => {:created_at => date}) 回答1: You can do it like this: date = Date.parse('january 5 2013') users = User.where(created_at: date.midnight..date.end_of_day) 回答2: Try this, User.where("Date(updated_at) = ?", "2018-02-9") 回答3: Yes, It is possible like: date = Date.parse("january 5 2013") users = User.where(created_at:

rails c not working in rails 5

半腔热情 提交于 2019-12-03 05:18:52
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 still gave the same error. it would be great if somebody can point out the mistake here. Running via Spring preloader in process 6457 /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require': dlopen(/Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9):

how can I run an initializer from the rails console?

时光毁灭记忆、已成空白 提交于 2019-12-03 03:11:01
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 problem - asside from being a newb and not understanding the console very well yet - is that I can't access the variables that are initialized in config/initializers/linkedin.rb . Any ideas on how to use the application initializers from within the console so that I don't have to run this by hand every time? Thanks! Try this: load "#{Rails.root}/config

Can I get the Ruby on Rails console to remember my command history, umm, better?

旧城冷巷雨未停 提交于 2019-12-03 02:55:07
问题 I'm using the console in Ruby on Rails 3.1.1, and I'm finding its command history (up arrow) to be really flaky. I've run the commands p = Product.by_name 'Acme' and p.add_search_term('Snipe') several times today, across several console sessions. Yet, when I reload the Ruby on Rails console, only the first one shows in my command history, not the second. Sometimes they are both there in the history after I reload the console. On top of that, I see commands in my history that are from several

Equivalence of Rails console for Node.js

自闭症网瘾萝莉.ら 提交于 2019-12-03 01:07:33
I am trying out Node.js Express framework, and looking for plugin that allows me to interact with my models via console, similar to Rails console. Is there such a thing in NodeJS world? If not, how can I interact with my Node.js models and data, such as manually add/remove objects, test methods on data etc.? It's simple: add a REPL to your program Create your own REPL by making a js file (ie: console.js) with the following lines/components: Require node's built-in repl: var repl = require("repl"); Load in all your key variables like db, any libraries you swear by, etc. Load the repl by using

Truncate table(s) with rails console

旧街凉风 提交于 2019-12-02 21:43:20
I have this testingdatabase which, by now, is stuffed with junk. Now I've done a few Table.destroy_all commands in the rails console which deletes all records and dependencies which is awesome. However; I'd like to truncate everything so the ID's etc. start at 1 again. Is there any way in Rails 3? Ravi Sankar Raju The accepted answer only works if you need to recreate the whole database. To drop a single table (with the callbacks) and to get the IDs to start from 1: Model.destroy_all # Only necessary if you want to trigger callbacks. ActiveRecord::Base.connection.execute("TRUNCATE #{table_name