# 20210209(화)

## 2021-02-09

### 1. 학습 날짜

* 2020-02-09

### 2. 학습 시간

* 11:00 \~ 24:00

### 3. 학습 범위 및 주제

* 백본 view, model, collection
* 루비온레일즈

### 4. 학습 목표

* appearance view 구현 완료하기
  * 친구 추가 기능 구현
  * 밴 기능 구현

### 5. 학습 정리

* [레일즈 액티브 레코드 find 활용](https://simian114.gitbook.io/blog/undefined/rubyonrails/find)
* [css 컴파일](https://simian114.gitbook.io/blog/undefined/rubyonrails/css)

### 6. 상세 학습 내용

* html 에 존재하는 모든 style 을 css 로 옮겼다.
  * 이때 이슈가 생겼는데, css 파일로 옮긴 내용이 페이지에 적용이 되지 않았던 것.
  * 이유는 밝혀내지 못했지만 의도적으로 assets 을 컴파일 해주면 된다. 이때 사용하는 명령은 `rails assets:precompile` 이다
* find\_by&#x20;
  * 백엔드에서 모델을 찾고 생성하는 과정에서 `find` 을 조금 더 잘 활용할 수 있게 됐다.
  * 기존에 id를 기반으로 특정 유저를 찾는다고 하면 `User.find_by_id` 와 같은 방법을 사용할 수 있었다.&#x20;
  * 하지만 특정 유저을 가지고 friendship 하나만을 찾기 위해서는 user\_id 와 friend\_id 두개가 필요했다. 만약 여기서 where 을 사용하면 단박에 찾을 수 있지만 단점이 배열로 리턴값이 생긴다는 것
  * 이 때  사용할수있는 방법이 find\_by를 늘여쓰는거다.아래처럼 하면 된다.
  * `find_by_user_id_and_friend_id(user_id, friend_id)`
* find\_or\_create\_by
  * 이 함수는 먼저 테이블에 인자로 들어온 데이터에 해당하는 레ㅋ드가 있는지를 찾고 없으면 추가한다.

### 7. 오늘 학습 내용에 대한 개인적인 총평

* 너무 속도가 느리다...&#x20;

### 8. 다음 학습 계획

* appearance view 세부 동작들 완성하기


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://simian114.gitbook.io/blog/undefined-1/diary/2021/february/20210209.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
