---
title: BoniO面試題(參考)
tags: 面試
---
BoniO
===
# ROR interview quiz
:::info
- 嘗試回答下述問題(不限制作答格式,可使用中英文或畫圖說明)
- 作答時間二個小時,不會的題目可以跳過不作答,歡迎 Google 尋找答案並搞懂後再回答,請適當分配作答時間。
:::
### Part I - Software Engineering
#### What is Cookie? Briefly describe how it works in practice.
```
write here
```
<br><br><br>
#### What is Session? Briefly describe how it works in practice.
```
write here
```
<br><br><br>
#### When you click a link that directs to `https://www.facebook.com/`, what would happen between the browser and the server? Please describe as much detail as you know.
```
write here
```
<br><br><br>
---
## Part II - Ruby and RoR:
#### What's the difference between `public`, `private`, and `protected` in Ruby?
```
write here
```
<br><br><br>
#### What is the difference between `Array#map` and `Array#each`?
```
write here
```
<br><br><br>
#### What is the differnece between `extend` and `include` in ruby?
```
write here
```
<br><br><br>
#### Explain what is `yield` in Ruby?
```
write here
```
<br><br><br>
#### What is difference between `render` and `redirect_to`?
```
write here
```
<br><br><br>
#### Please read the following table and answer the questions:
![schools_table](https://i.imgur.com/Tu62Mg2.png)
##### Use Rails ORM to list all schools that code is null.
```
write here
```
<br><br><br>
##### Use Rails ORM to list all schools that has duplicate code.
```
write here
```
<br><br><br>
##### Finish the model code below:
```ruby=
class School < ApplicationRecord
# ===============================================
# 教育部學校代碼 - 學校級別對照表
# (根據學校代碼左邊算來第四碼判斷)
# ===============================================
# 5 國民中學
# 6┐
# 7┤國民小學
# 8┘
# ===============================================
# 透過學校代碼計算學校級別
def self.stage(code:)
write here
write here
end
end
School.stage(code: '011601') # => '國民小學'
School.stage(code: '054702') # => '國民小學'
School.stage(code: '044518') # => '國民中學'
```
<br><br>
#### Please read the following code examples and answer the questions:
```ruby=
class User < ApplicationRecord
def admin?
admin?(id)
end
def self.admin?(id)
User.find_by(id: id)&.has_role?(:admin)
end
end
User.admin?(User.last.id) # => true
User.last.admin? # => ?
```
##### What is the result of line 12?
```
write here
```
<br><br><br>
##### If line 12 raise errors, how would you fix it?
```
write here
```
<br><br><br>
#### Please read the following codes and answer the questions:
```ruby=
# db/schema.rb
create_table :comments do |t|
t.integer :post_id
t.integer :author_id
t.string :content
end
```
```ruby=
# app/controllers/comments_controller.rb
class CommentsController < ApplicationController
def users_comments
comments = Post.all.map(&:comments).flatten
@user_comments = comments.select do |comment|
comment.author.username == params[:username]
end
end
end
```
##### What’s the issue with the controller code?
```
write here
```
<br><br><br>
##### How would you fix it by using `includes` method?
```
write here
```
<br><br><br>
##### How would you fix it without the use of `includes`?
```
write here
```
<br><br><br>
#### Please finish code below and answer the questions:
```ruby=
# db/schema.rb
create_table :books do |t|
t.string :name
t.string :author
end
create_table :bookstore do |t|
t.string :name
end
create_table :book_bookstores do |t|
t.integer :inventory_quantity
write here
end
```
```ruby=
# app/models/book.rb
class Book < ApplicationRecord
write here
end
# app/models/bookstore.rb
class Bookstore < ApplicationRecord
write here
end
# app/models/book_bookstore.rb
class BookBookstore < ApplicationRecord
write here
end
```
<br>
##### Now have the following information
```ruby=
books = [
{
name: "Harry Potter and the Philosopher's Stone",
author: 'J. K. Rowling',
}
]
bookstore = [
{
name: 'Diagon Alley'
},
{
name: 'Butterbeer'
}
]
```
##### Harry Potter and the Philosopher's Stone need 3 inventory_quantity in Diagon Alley
```
write here
```
##### Harry Potter and the Philosopher's Stone need 4 inventory_quantity in Butterbeer
```
write here
```
##### How many copies of Harry Potter and the Philosopher's Stone are currently in all bookstores?
```
write here
```
<br><br><br>
---
## Part III - SQL:
#### How do you detect `slow queries`?
```
write here
```
<br><br><br>
#### What is an `index` and why would you use it?
```
write here
```
<br><br><br>
#### What is `SQL injection`?
```
write here
```
<br><br><br>
---
## Part IV - Other Knowledges
#### What’s `redis`? How would you use it in a web application?
```
write here
```
<br><br><br>
#### What's `load balance`? why would you use it?
```
write here
```
<br><br><br>
#### How do you benchmark your website performance? and how to ensure website can handle 10000 active users?
```
write here
```