---
# System prepended metadata

title: Ruby問題集
tags: [Ruby]

---

###### tags: `Ruby`

# Ruby問題集

## Q: 碰到 'An error occurred while installing json (1.8.6), and Bundler cannot continue'怎麼辦?

### A: 執行 'sudo apt install ruby-dev'

## Q: 使用VS Code時，碰到"command /usr/local/bin/rubocop returns empty output! please check configuration."

### A: ctrl+shift+P -> 輸入settings -> 找到Open Settings(UI) -> 搜尋rubocop -> 在Execute Path裡輸入/home/youthink/.rbenv/versions/3.1.2/bin/ -> 隨意修改檔案看是否又有報錯

## Q: How to use multiple assignment with a ternary operator?

### A: Here is the correct syntax for multiple assignment using a ternary operator:

	foo, bar = baz ? [1, 2] : [3, 4]
    
## Q: What is "Could not find 'json' (>= 1.7.7, ~> 1.7) among 244 total gem(s)" means?

### A: The json requirement has two parts. The first is >= 1.7.7 meaning the Gem must be greater than or equal to 1.7.7. 2.0.2 is, in fact, greater than 1.7.7, so you satisfy that requirement. However, the second part of that is that it must also be ~> 1.7 (pronounced "tiddle-wakka") is what's called a Pessimistic Constraint. It required that the first elements of the version number match but the last can be greater than or equal to the number given. So, for example, 1.7.0 would satisfy the constraint. As would 1.7.9 or 1.9.9, or even 1.423.8. However, 2.0.0 would fail that constraint because the major version number doesn't match the given value of "1".

## Q: Rack session: I would like to ask about the MVC test problem, in order to execute MVC test need to have actionpack gem, which depends on (rack ~> 2.0, >= 2.2.0), but (rack-session, ~> 0.3) depends on (rack >= 3.0.0.beta1). Does anybody know how to solve it?

### A: bundle clean --force

## Q: SQLite: no such table

### A: RACK_ENV=test when drop and migrate db.

## Q: VSCode rdbg Ruby Debugger can not work

### A: reinstall VSCode rdbg Ruby Debugger to v0.0.11

## Q: uninitialized constant Rack:MethodOverride

### A: require 'rack' into app.rb

## Q: Webdrivers::BrowserNotFound: Failed to determine Chrome binary location.

### A: Just check if your OS has already installed Chrome

## Q: WebDriverException: Message: unknown error: net::ERR_CONNECTION_REFUSED

### A: Need to open web on the Chrome first, then you can run test

## Q: How to kill process?

### A: netstat -lpn | grep "Port-number"
E.g: netstat -lpn | grep 9090
    
## Q: How to run App test?

### A: Press F5 and then type "bundle exec puma -p Port-number"
E.g: bundle exec puma -p 9090