Pre-Filled Prompt in Ruby
You can do it with RbReadline:
require 'rubygems'
require 'rb-readline'
module RbReadline
def self.prefill_prompt(str)
@rl_prefill = str
@rl_startup_hook = :rl_prefill_hook
end
def self.rl_prefill_hook
rl_insert_text @rl_prefill if @rl_prefill
@rl_startup_hook = nil
end
end
RbReadline.prefill_prompt("Previous query")
str = Readline.readline("Enter query: ", true)
puts "You entered: #{str}"
Pre-fill Rails HTML form with variable
If you look at number_field
, you pass in number fields value, class and other options in a single block so try this:
<%= f.number_field :priceOffer, :value => @product.price, class:"form-control" %>
Print editable to console in Ruby
There are similar questions here and here
However, the solutions there don't seem to work as expected, so it looks this is ruby version or platform dependent?
For example, this does not work for me, but also does not throw an error.
require "readline"
filename = Readline.insert_text("untitled.txt").readline("Enter a filename:")
print filename
But since it looks much better, and should work according to the documentation for ruby >= 2, I am leaving it there for now.
The following works on my system (ruby 2.3.1, OS X)
require "readline"
require 'rb-readline'
module RbReadline
def self.prefill_prompt(str)
@rl_prefill = str
@rl_startup_hook = :rl_prefill_hook
end
def self.rl_prefill_hook
rl_insert_text @rl_prefill if @rl_prefill
@rl_startup_hook = nil
end
end
RbReadline.prefill_prompt("untitled.txt")
str = Readline.readline("Enter a filename:", true)
puts "You entered: #{str}"
Related Topics
Error Install Rubyracer with Error "Invalid Gem: Package Is Corrupt"
How to Remove Duplicates in a Hash in Ruby on Rails
How to Fix an Accidental 'Sudo Bundle Install Dir_Name'
Using Compass from Ruby (Not Shell)
What Does +@ Mean as a Method in Ruby
How to Redefine Fixnum's + (Plus) Method in Ruby and Keep Original + Functionality
How to Write an Rspec Test for a Ruby Method That Contains "Gets.Chomp"
Get Chromes Console Log via Ruby Webdriver
Make Rails Ignore Daylight Saving Time When Displaying a Date
Rails 4 How to Call Accessible_Attributes from Model
How to Convert Ppt to Images in Ruby
How to Mark a Cucumber Scenario as Pending
Why Is Counting Letters Faster Using String#Count Than Using String#Chars in Ruby
How the Anchor \Z and \G Works in Ruby
Cannot Load Such File -- MySQL2/2.4/Mysql2 (Loaderror) - Windows