글
임시 방편으로
해당 .rb 파일에서 직접 생성해서 사용한다.
logger = Logger.new(STDOUT)
logger.debug "initialize=======================================(+)"
임시 방편으로
해당 .rb 파일에서 직접 생성해서 사용한다.
logger = Logger.new(STDOUT)
logger.debug "initialize=======================================(+)"
logger.debug "check public/uploads"
Dir.mkdir("public/uploads") unless Dir.exist?("public/uploads")
logger.debug "check public/uploads/tmp"
Dir.mkdir("public/uploads/tmp") unless Dir.exist?("public/uploads/tmp")
한번에 2 depth를 생성할 수는 없는 것 처럼 동작한다.
옵션이 있을지 모르지만.
일단 폴더 확인 로직 추가한다.
stuff - a local variable : 해당 모듈 혹은 action 이내에서만 처리가능한 선언
@stuff - an object variable (one per object) - 해당 모듈 뿐 아니리 연결된 html.erb에서도 사용할 수 있는 선언
@@stuff - a class variable (just one for a whole class of objects) - @와 뭐가 다른지 더 고민해야 함.
$stuff - a global variable (just one for the program) - 마치 응용프로그램의 전역변수 처럼 동작하는데 그 메모리 해제나 기타 이슈가 있는지 확인해야 한다.
명확하게 이해하지 못하고 있어서 메모 식으로 정리함.
Rails에서 주소에 params을 추가해서 데이터를 전송하게 된다.
다음과 같은 식으로
http://localhost:3000/admin_report/qc_statistics/utilization?from=2016-01-04&to=2016-04-04&ids%5B%5D=1
그럼 from / to / ids 등의 값이 전달 받은 페이지에 인자로 전달 된다.
이 때 전달 받은 페이지쪽에서 해당 params을 parsing 해서 처리하는 방법을 정리한다.
var ids = getQueryArrayVariable("ids[]"); 해당 함수를 이용해서 전달 받은 "AAA"="BBB"를 하게 되면 AAA를 검색어로 넣으면 BBB가 나오게 된다.
아직 확실히 정리하지 못하고 있다 ㅠㅠ
Rails에서 MySQL을 많이 쓰지만 MariaDB 쓰는 것도 매우 쉽다.
단 rubygems.org에서 Maria 관련해서 찾아봐야 별거 안 나온다.
Maria DB도 mysql2 라는 Gem을 쓴다.
그러므로.
1. ruby 설치
2. rails 설치
3. mysql connector 설치
4. mariaDB 설치. - http://mariadb.org/download/
[입력 받기]
웹서비스가 아닌 상태에서 windows command 창에서 문자를 입력 받을 때
STDOUT.flush
key = gets.chomp - 사용자가 값을 입력한 후에 엔터를 입력할 때 이 '엔터' 문자를 제거하는 기능
gets으로 수집한 값은 문자열로 인식되는데.
.to_i는 정수(integer)로 변환
.to_f는 float으로 변환
.to_s는 문자열로 변환
[출력할 때]
print - 특정값을 출력
puts - 특정값을 출력한 다음 줄 바꿈 한다.
byte[] data = { 1, 2, 4, 8, 16, 32 };
string hex = BitConverter.ToString(data);
해당 string을 출력하면
01-02-04-08-10-20
"-"이 거슬린다면 replace를 쓰자.
string hex = BitConverter.ToString(data).Replace("-", string.Empty);
모델에서 데이터를 추출할 때 쿼리에서의 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가 됩니다.
RECENT COMMENT