검색결과 리스트
Rails에 해당되는 글 14건
- 2016.03.10 [Rails]Maria DB 사용하기
- 2016.02.18 [Rails]model에서의 not like 동작 하게 하기.
- 2016.02.17 [Rails]Rails에서 routes.rb에 등록된 내용을 직관적으로 볼 수 있는 방법
- 2016.02.16 [Rails] 특정 위치에 controller 생성하기
Rails에서 MySQL을 많이 쓰지만 MariaDB 쓰는 것도 매우 쉽다.
단 rubygems.org에서 Maria 관련해서 찾아봐야 별거 안 나온다.
Maria DB도 mysql2 라는 Gem을 쓴다.
그러므로.
1. ruby 설치
2. rails 설치
3. mysql connector 설치
4. mariaDB 설치. - http://mariadb.org/download/
모델에서 데이터를 추출할 때 쿼리에서의 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
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가 됩니다.
이 때 생성 경로 폴더 앞에 "/"를 붙이게 되면
삭제를 하고자 할때는 "const_defined?"가 포함된 wrong constant name (nameerror)가 뜨니 조심해야 한다.
rails destroy controller observations/ketone
이때 상위 폴더는 삭제 되지 않는다.
RECENT COMMENT