Rails에서 MySQL을 많이 쓰지만 MariaDB 쓰는 것도 매우 쉽다.


단 rubygems.org에서 Maria 관련해서 찾아봐야 별거 안 나온다.


Maria DB도 mysql2 라는 Gem을 쓴다. 


그러므로.


1. ruby 설치

2. rails 설치

3. mysql connector 설치

4. mariaDB 설치. - http://mariadb.org/download/


by 무위자연 2016. 3. 10. 17:39

모델에서 데이터를 추출할 때 쿼리에서의 not like를 구현하고 싶을때.


@perms = PaperTrail::Version.where(item_type: "Device").where.not(object_changes: ["%last_qc%"]).order('created_at DESC').limit(50)

- 이렇게 했을 경우에 쿼리는 다음과 같이 나오게 된다.

select  * from versions where item_type = "device" and ( object_changes != '%last_qc%') order by created_at DESC limit 50

이 것의 의미는 "%last_qc%"를 비교하는 쿼리가 된다. 즉 "" 안에 있는 %가 like가 아닌 % 문자열로 인식하게 된다.


PaperTrail::Version.where(item_type: "Device").where.not("object_changes LIKE?","%last_qc%").order('created_at DESC').limit(50)

> 컬럼명 안에 "LIKE?"를 넣어서 not이 아닌 not like로 인식하는 쿼리가 되게 한다.


select  * from versions where item_type = "device" and ( not(object_changes LIKE '%last_qc%')) order by created_at DESC limit 50



by 무위자연 2016. 2. 18. 17:24

Rails에서 routes.rb에 등록된 내용을 직관적으로 볼 수 있는 방법이 있어서 공유 합니다.

 

http://localhost:3000/rails/info/routes

동적 링크 helper 에서 사용할 경로가 “Helper” 열이며 실제로 해당 Helper를 호출했을 때 연결되는 action 4번째 열입니다.

. device_dhistory_index_path 호출하면 device/dhistory#index 호출되게 됩니다.

코드 상의 .

<li class="<%= 'current' if secondary_navigation?(:dhistory) %>">

                          <a href="<%= device_dhistory_index_path %>"> 여기서 호출

                            <span class="icon"><i class="icon5 i-arrow-right-3"></i></span>

                            <span class="txt"><%= I18n.t('menu.side.device.device_history') %></span>

                          </a>

                        </li>

 

이 때 호출 되는 페이지는 view / device / dhistory/index.html.erb가 됩니다.

by 무위자연 2016. 2. 17. 11:24
cotroller를 원하는 path에 추가하고 싶을때

rails generate controller device22/device_history

이미 있는 폴더를 지정하면 그 폴더 이하에 생기고

없는 폴더라면 폴더를 생성한 다음에 그 하위에 생긴다.

이 때 생성 경로 폴더 앞에 "/"를 붙이게 되면 

삭제를 하고자 할때는 "const_defined?"가 포함된 wrong constant name (nameerror)가 뜨니 조심해야 한다.


rails destroy controller observations/ketone


이때 상위 폴더는 삭제 되지 않는다.

by 무위자연 2016. 2. 16. 10:56
| 1 2 |