<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1019502425077729251</id><updated>2024-09-19T06:11:02.673-07:00</updated><category term="Ruby on Rails"/><category term="Model"/><category term="Android"/><category term="Controller"/><category term="vinyl"/><category term="사진"/><category term="404"/><category term="500"/><category term="Exception"/><category term="Java"/><category term="Network"/><category term="Phusion Passenger"/><category term="SQLServer"/><category term="Validation"/><category term="ajax"/><category term="has_and_belongs_to_many"/><category term="javascript"/><category term="this"/><title type='text'>Rails on me :)</title><subtitle type='html'>with ruby core and CGIs</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-4700275025681191459</id><published>2011-12-20T23:51:00.001-08:00</published><updated>2011-12-20T23:51:28.832-08:00</updated><title type='text'>오랜만에 포스팅</title><content type='html'>테스트 입니다.</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/4700275025681191459/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/4700275025681191459' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4700275025681191459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4700275025681191459'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2011/12/blog-post.html' title='오랜만에 포스팅'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-4650336373368098318</id><published>2010-11-13T00:41:00.001-08:00</published><updated>2010-11-13T05:58:12.427-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="this"/><title type='text'>Javascript의 this 매개변수의 다양성</title><content type='html'>자바스크립트에는 함수를 호출하는데 메서드 호출패턴, 함수호출 패턴, 생성자 호출패턴, apply 호출패턴이라는 네가지 패턴이 있다. 각각의 패턴에 따라 this 라는 매개변수를 다르게 초기화 한다.&lt;br /&gt;
&lt;br /&gt;
1. 메서드 호출 패턴&lt;br /&gt;
&lt;br /&gt;
함수를 객체의 속성에 저장하는 경우 이 함수를 메서드라 부르며, 이때 this는 &lt;b&gt;메서드를 포함하는 객체에 바인딩&lt;/b&gt;된다.&lt;br /&gt;
&lt;br /&gt;
var oj = {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;value : 99,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;get_value : function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;alert(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.value);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
oj.get_value(); &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;// 99&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
2. 함수 호출 패턴&lt;br /&gt;
&lt;br /&gt;
함수가 객체의 속성이 아닌 단지 함수(function)로서 호출될때, this는 &lt;b&gt;전역객체에 바인딩&lt;/b&gt;된다.&lt;br /&gt;
&lt;br /&gt;
var doSomething = function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;alert(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;); &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;// window&lt;/span&gt;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
3. 생성자 호출 패턴&lt;br /&gt;
&lt;br /&gt;
함수를 new라는 전치 연산자와 함께 호출하면, 호출한 함수의 prototype 속성값에 연결된 (숨겨진) 링크를 갖는 객체가 생성되고, this 는 이 &lt;b&gt;새로운 객체에 바인딩&lt;/b&gt;된다. &lt;br /&gt;
&lt;br /&gt;
var Obj = function (str) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;this.status = str;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
Obj.prototype.get_status = function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.status;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
var myObj = new Obj(&quot;going&quot;);&lt;br /&gt;
myObj.get_status() &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;// &quot;going&quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. apply(또는 call) 호출 패턴&lt;br /&gt;
&lt;br /&gt;
apply 매서드는 &lt;b&gt;this의 값을 선택할 수 있도록&lt;/b&gt; 해준다. apply 메서드에는 매개변수 두개가 있는데, 첫째는 this 에 묶이게 될 값이며, 두번째는 매개변수들의 배열이다.&lt;br /&gt;
&lt;br /&gt;
var statusOj = {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;status : &#39;Z-OK&#39;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;* 3번에서 정의한 Obj 객체를 이용하자&lt;/span&gt;&lt;br /&gt;
Obj.prototype.get_status.apply(statusOj); &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;// &quot;Z-OK&quot;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/4650336373368098318/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/4650336373368098318' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4650336373368098318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4650336373368098318'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/11/javascript-this.html' title='Javascript의 this 매개변수의 다양성'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-4257120231578196233</id><published>2010-07-15T18:36:00.000-07:00</published><updated>2011-02-05T23:20:21.107-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Network"/><title type='text'>파일 이어받기 구현</title><content type='html'>[현재 작성 중인 포스트]&lt;br /&gt;
&lt;br /&gt;
===============================================================================================================&lt;br /&gt;
다운로드 요청&lt;br /&gt;
request&lt;br /&gt;
특별한 파라미터 없음&lt;br /&gt;
&lt;br /&gt;
response&lt;br /&gt;
07-15 20:24:29.619: INFO/response *name* and *value*(8182): Date = Thu, 15 Jul 2010 11:27:16 GMT&lt;br /&gt;
07-15 20:24:29.619: INFO/response *name* and *value*(8182): Server = Apache/2.2.12 (Ubuntu)&lt;br /&gt;
07-15 20:24:29.629: INFO/response *name* and *value*(8182): Last-Modified = Mon, 05 Jul 2010 01:58:21 GMT&lt;br /&gt;
07-15 20:24:29.629: INFO/response *name* and *value*(8182): ETag = &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;a0ac5-1400000-48a9a4570a8c9&lt;/span&gt;&quot;&lt;br /&gt;
07-15 20:24:29.629: INFO/response *name* and *value*(8182): Accept-Ranges = bytes&lt;br /&gt;
07-15 20:24:29.629: INFO/response *name* and *value*(8182): Content-Length = 20971520&lt;br /&gt;
07-15 20:24:29.629: INFO/response *name* and *value*(8182): Keep-Alive = timeout=15, max=100&lt;br /&gt;
07-15 20:24:29.629: INFO/response *name* and *value*(8182): Connection = Keep-Alive&lt;br /&gt;
07-15 20:24:29.639: INFO/response *name* and *value*(8182): Content-Type = application/zip&lt;br /&gt;
&lt;br /&gt;
07-16 09:52:37.606: INFO/**status code**(13384): &lt;b&gt;HTTP/1.1 200 OK&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
! etag 가 반환된다.&lt;br /&gt;
다운로드 이어받기를 구현하려면,&lt;br /&gt;
(1)&amp;nbsp;이 etag 를 기억하고,&lt;br /&gt;
(2) 현재까지 다운받을 양을 기억해둬야 다음 이어받기 요청시 서버가 이를 자동으로 처리해준다(Apache 의 경우, 그 외 다른 서버는 모르겠다).&lt;br /&gt;
&lt;br /&gt;
===============================================================================================================&lt;br /&gt;
파일 이어서 다운받기 요청시,&lt;br /&gt;
&lt;br /&gt;
request&lt;br /&gt;
07-15 20:28:02.999: INFO/request *name* and *value*(8467): Range = &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: magenta;&quot;&gt;bytes=6295290-&lt;/span&gt;&lt;br /&gt;
07-16 09:54:17.046: INFO/request *name* and *value*(13608): If-Range = &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;a0ac5-1400000-48a9a4570a8c9&lt;/span&gt;&quot;&lt;br /&gt;
&lt;br /&gt;
response 시,&lt;br /&gt;
07-15 20:28:02.999: INFO/response *name* and *value*(8467): Date = Thu, 15 Jul 2010 11:30:49 GMT&lt;br /&gt;
07-15 20:28:02.999: INFO/response *name* and *value*(8467): Server = Apache/2.2.12 (Ubuntu)&lt;br /&gt;
07-15 20:28:02.999: INFO/response *name* and *value*(8467): Last-Modified = Mon, 05 Jul 2010 01:58:21 GMT&lt;br /&gt;
07-15 20:28:02.999: INFO/response *name* and *value*(8467): ETag = &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;a0ac5-1400000-48a9a4570a8c9&lt;/span&gt;&quot;&lt;br /&gt;
07-15 20:28:02.999: INFO/response *name* and *value*(8467): Accept-Ranges = bytes&lt;br /&gt;
07-15 20:28:02.999: INFO/response *name* and *value*(8467): Content-Length = 14676230&lt;br /&gt;
07-15 20:28:03.009: INFO/response *name* and *value*(8467): Content-Range = &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: magenta;&quot;&gt;bytes 6295290-20971519/20971520&lt;/span&gt;&lt;br /&gt;
07-15 20:28:03.009: INFO/response *name* and *value*(8467): Keep-Alive = timeout=15, max=100&lt;br /&gt;
07-15 20:28:03.009: INFO/response *name* and *value*(8467): Connection = Keep-Alive&lt;br /&gt;
07-15 20:28:03.009: INFO/response *name* and *value*(8467): Content-Type = application/zip&lt;br /&gt;
&lt;br /&gt;
07-16 09:45:55.276: INFO/**status code**(13117): &lt;b&gt;HTTP/1.1 206 Partial Content&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
! etag 가 동일하다&lt;br /&gt;
&lt;br /&gt;
================================================================================================================&lt;br /&gt;
파일 이어서 다운받기 요청시 (하지만 서버의 다운받을 파일이 변경되었을 때!!),&lt;br /&gt;
&lt;br /&gt;
request&lt;br /&gt;
07-16 09:54:17.046: INFO/request *name* and *value*(13608): Range = &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: magenta;&quot;&gt;bytes=12388474-&lt;/span&gt;&lt;br /&gt;
07-16 09:54:17.046: INFO/request *name* and *value*(13608): If-Range = &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;a0b25-2137785-48b76a85b3857&lt;/span&gt;&quot;&lt;br /&gt;
&lt;br /&gt;
response&lt;br /&gt;
07-16 09:54:17.276: INFO/response *name* and *value*(13608): Date = Fri, 16 Jul 2010 00:57:07 GMT&lt;br /&gt;
07-16 09:54:17.276: INFO/response *name* and *value*(13608): Server = Apache/2.2.12 (Ubuntu)&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): Last-Modified = Fri, 16 Jul 2010 00:56:19 GMT&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): ETag = &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;a0b25-321f627-48b76afd27997&lt;/span&gt;&quot;&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): Accept-Ranges = bytes&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): Content-Length = 40168877&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): Keep-Alive = timeout=15, max=100&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): Connection = Keep-Alive&lt;br /&gt;
07-16 09:54:17.286: INFO/response *name* and *value*(13608): Content-Type = application/zip&lt;br /&gt;
&lt;br /&gt;
07-16 09:54:17.296: INFO/**status code**(13608):&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;b&gt;HTTP/1.1 200 OK&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
! etag 가 다르다 :)&lt;br /&gt;
응답코드도 206 이 아닌 200 이다.&lt;br /&gt;
서버 파일이 변경되었기에, 요청 header 의 Range 헤더는 무시되고, 처음부터 다운로드 받는다. &lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/4257120231578196233/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/4257120231578196233' title='2개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4257120231578196233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4257120231578196233'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/07/blog-post.html' title='파일 이어받기 구현'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-5135141077643524756</id><published>2010-07-12T04:08:00.000-07:00</published><updated>2010-07-15T02:00:32.340-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><title type='text'>Android : Network Exception 유형 간단 정리</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;요청이 무사히 전달되면,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;-&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;HTTP_OK(200)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt; 존재하지 않는 주소로 요청을 보낼 때,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;-&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;java.net.UnknownHostException 발생&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt; 존재하는 주소지만, 요청한 경로(혹은 파일)를 찾을 수 없을 때,&lt;/span&gt;&lt;br /&gt;
-&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;HTTP_NOT_FOUND(404)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt; 존재하는 주소지만, 응답을 보내주는 웹서버가 없거나 비활성화인 경우,&lt;/span&gt;&lt;br /&gt;
-&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;IOException 발생 (java.net.ConnectionException)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt; 인증실패시,&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;-&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;HTTP_UNAUTHORIZED(401)&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;인터넷 연결이 안된 상태에서 connection 시도할 경우,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
-&lt;br /&gt;
(1) &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;IOException&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
(2) &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;SocketException&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
위 두 exception 이 순차적으로 발생한다.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;다운로드중 인터넷이 끊겼을 때,&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
-&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;* exception 발생 시키려면 반드시,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;HttpURLConnection 객체에 &lt;b&gt;setReadTimeout()&lt;/b&gt; 으로 시간을 적용시켜야 한다.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
*만약, HttpClient 를 사용한다면&amp;nbsp;client.getParams().setParameter(&quot;http.socket.timeout&quot;, 5000);&lt;br /&gt;
위와 같이 적용해준다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
인터넷 끊김 후 위에 적용한 시간이 흐른 뒤,&lt;br /&gt;
&lt;br /&gt;
(1) &lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;SocketTimeoutException&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
이 발생한다.</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/5135141077643524756/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/5135141077643524756' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/5135141077643524756'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/5135141077643524756'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/07/android-network-exception.html' title='Android : Network Exception 유형 간단 정리'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-8067871925595363643</id><published>2010-06-20T19:39:00.000-07:00</published><updated>2010-06-20T19:40:40.263-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="Controller"/><title type='text'>AJAX in Rails with Authenticity Token</title><content type='html'>&lt;div class=&quot;post_header&quot;&gt;&lt;h4&gt;출처 :&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;a href=&quot;http://archive.alwaysmovefast.com/ajax-in-rails-with-authenticity-token.html&quot;&gt;http://archive.alwaysmovefast.com/ajax-in-rails-with-authenticity-token.html&lt;/a&gt;&lt;/span&gt;&lt;/h4&gt;&lt;div&gt;ajax 요청을 post 로 보낼 경우, InvalidAuthenticityToken 에러가 발생한다. 이를 해지해줄 방법은 다음과 같다.&amp;nbsp;&lt;/div&gt;&lt;h4&gt;AJAX in Rails with Authenticity Token&lt;/h4&gt;&lt;span class=&quot;post_date&quot; style=&quot;float: left;&quot;&gt;January 30, 2008&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;post_body&quot;&gt;When you use active_record_store instead of the cookie-based default, you need to uncomment the line in controllers/application.rb that says protect_from_forgery :secret =&amp;gt; &#39;blah&#39;. This makes sure all your HTML and JavaScript requests are coming from your web application. It essentially protects you from something called &quot;Cross-site request forgery&quot; by embedding a token into your web forms.&lt;br /&gt;
&lt;br /&gt;
As a side note, it&#39;s really not giving you much security at all, but that might be better left for another blog post.&lt;br /&gt;
&lt;br /&gt;
I was banging my head against the wall yesterday trying to figure out why a custom Ajax.Updater wasn&#39;t working and I kept getting an ActionController::InvalidAuthenticityToken exception. I decided to dig into the request_forgery_protection.rb file in actionpack-*/lib/action_controller and found that for custom requests, you need to include the authenticity_token yourself by taking advantage of the form_authenticity_token helper. When building the updater&#39;s request url I just added &quot;&amp;amp;authenticity_token=&quot; to the end and everything was fine.&lt;br /&gt;
&lt;br /&gt;
Another way would be to not use the forgery protection at all for that action by including this in your controller: &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;protect_from_forgery :except =&amp;gt; [:updater]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You can also completely remove forgery protection from a controller by doing &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;skip_before_filter :verify_authenticity_token&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Back to the vulnerability of your web forms: I imagine this does protect your web application from someone hosting a form on their site that posts to your site. However, if someone really wants to spam some stuff they&#39;ll scrape your page with cookies enabled on their scraping software, scrape your form&#39;s fields (which include the authenticity_token hidden field) and POST to their heart&#39;s desire.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/8067871925595363643/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/8067871925595363643' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/8067871925595363643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/8067871925595363643'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/06/ajax-in-rails-with-authenticity-token.html' title='AJAX in Rails with Authenticity Token'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-6424504890910203091</id><published>2010-05-31T07:42:00.000-07:00</published><updated>2010-05-31T07:44:51.303-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vinyl"/><category scheme="http://www.blogger.com/atom/ns#" term="사진"/><title type='text'>vinyl - 정철씨, 성진대리 마지막 날</title><content type='html'>&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;정철씨가 계약기간이 끝나 오늘 떠나게 됬다. 점심시간 맥주마시며,&amp;nbsp;조촐한 짧은 송별회를 가졌다.&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRG_Lj-rQHG2snlu3-up_c1b-Qvxal1zX5t00tKZ7ab-oSUIwX4CiFOoaDbjANKfr5gFvaPcnYV7GnCZa88Ke1t8ZWg7zio7G0Ecebi85aU8byHBJ0vNbsUuzfrasbPIuLYDmzGcUV3Y2V/s1600/IMG20100531_001.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; gu=&quot;true&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRG_Lj-rQHG2snlu3-up_c1b-Qvxal1zX5t00tKZ7ab-oSUIwX4CiFOoaDbjANKfr5gFvaPcnYV7GnCZa88Ke1t8ZWg7zio7G0Ecebi85aU8byHBJ0vNbsUuzfrasbPIuLYDmzGcUV3Y2V/s640/IMG20100531_001.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;다들 화알짝~ &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6_wQTEMVS6BbQBOZedQY7ZspPx8X3dYN_a9PsxG1Lwu8Y3XqnErY_TRlm9ZEIO_00NS_9IGENVxFaeJMBUUUIX7OuoNSuKYWxyJZn6hBVDw5Euh6fSqH_WmgQndTEIOPm0KiCwV280Uul/s1600/IMG20100531_004.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; gu=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6_wQTEMVS6BbQBOZedQY7ZspPx8X3dYN_a9PsxG1Lwu8Y3XqnErY_TRlm9ZEIO_00NS_9IGENVxFaeJMBUUUIX7OuoNSuKYWxyJZn6hBVDw5Euh6fSqH_WmgQndTEIOPm0KiCwV280Uul/s320/IMG20100531_004.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;둘이 사귄다. &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkb413xnhFE-eCRkvgLJyiOZGn2gWlfV6cptMKENYXt6A2HNyLP1FXRCd6gQI-5WCliVYDtTL_MToN7m9QMSSyBwFnjzDbOq33vfAYWTMcF_fC9oLagNd126Yytjp0IWAHmG1O04qzyAU4/s1600/IMG20100531_005.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; gu=&quot;true&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkb413xnhFE-eCRkvgLJyiOZGn2gWlfV6cptMKENYXt6A2HNyLP1FXRCd6gQI-5WCliVYDtTL_MToN7m9QMSSyBwFnjzDbOq33vfAYWTMcF_fC9oLagNd126Yytjp0IWAHmG1O04qzyAU4/s640/IMG20100531_005.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;성진대리님 새로운 직장 적응 잘하고, 아이폰 개발 건승하세요 ! &lt;/div&gt;&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie1DJRy0mIaSC2qcNFWMHxexWOppXACqQCWTpiIXyjlYtajxmb_F0aiuBRqQ6NecejtAQ8VVxs7CFyU9S2yuUxFB7oZfaB6Daxw2_Y2CcXRBX9KOBvkVUAtwcPH8pY48TJvrzRytNqQDzt/s1600/IMG20100531_007.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; gu=&quot;true&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie1DJRy0mIaSC2qcNFWMHxexWOppXACqQCWTpiIXyjlYtajxmb_F0aiuBRqQ6NecejtAQ8VVxs7CFyU9S2yuUxFB7oZfaB6Daxw2_Y2CcXRBX9KOBvkVUAtwcPH8pY48TJvrzRytNqQDzt/s400/IMG20100531_007.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;완휘선임, 나, 그리고 정철씨. &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img height=&quot;72&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRG_Lj-rQHG2snlu3-up_c1b-Qvxal1zX5t00tKZ7ab-oSUIwX4CiFOoaDbjANKfr5gFvaPcnYV7GnCZa88Ke1t8ZWg7zio7G0Ecebi85aU8byHBJ0vNbsUuzfrasbPIuLYDmzGcUV3Y2V/s320/IMG20100531_001.jpg&quot; style=&quot;filter: alpha(opacity=30); left: 533px; mozopacity: 0.3; opacity: 0.3; position: absolute; top: 252px; visibility: hidden;&quot; width=&quot;96&quot; /&gt; &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhq3FKChl1KAasWhmwNALSJYLF74sfDZyPwL6uuOpa7eSLM4iplM83hIW7Kl_hyphenhyphen7YKE_Gj8q519uTLBBd6PEU_bQA7TauddoSqWf5jnyzftXs4S_wbM2je7eauw85Laym3yz78cZcmVmCw/s1600/IMG20100531_002.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; gu=&quot;true&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhq3FKChl1KAasWhmwNALSJYLF74sfDZyPwL6uuOpa7eSLM4iplM83hIW7Kl_hyphenhyphen7YKE_Gj8q519uTLBBd6PEU_bQA7TauddoSqWf5jnyzftXs4S_wbM2je7eauw85Laym3yz78cZcmVmCw/s400/IMG20100531_002.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbhjU1k1LVUZ0jGIfawN71gNC2A3XQDjEefMMs0k3I8zFbZJ3ppibGDmZCjcyQ_sO69_sjk64pFe9Rj2Df0murBrxQiWWfhfQsazvCfgw7u6tu3XA6p-r3Q2FsJ8e3MbGZtCitRk4jstlW/s1600/IMG20100531_008.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; gu=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbhjU1k1LVUZ0jGIfawN71gNC2A3XQDjEefMMs0k3I8zFbZJ3ppibGDmZCjcyQ_sO69_sjk64pFe9Rj2Df0murBrxQiWWfhfQsazvCfgw7u6tu3XA6p-r3Q2FsJ8e3MbGZtCitRk4jstlW/s320/IMG20100531_008.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;그리고 퇴근하는길, 두포과장님의 간지컷. &lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/6424504890910203091/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/6424504890910203091' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/6424504890910203091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/6424504890910203091'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/05/vinyl_31.html' title='vinyl - 정철씨, 성진대리 마지막 날'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRG_Lj-rQHG2snlu3-up_c1b-Qvxal1zX5t00tKZ7ab-oSUIwX4CiFOoaDbjANKfr5gFvaPcnYV7GnCZa88Ke1t8ZWg7zio7G0Ecebi85aU8byHBJ0vNbsUuzfrasbPIuLYDmzGcUV3Y2V/s72-c/IMG20100531_001.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-2138444979940517558</id><published>2010-05-16T07:22:00.000-07:00</published><updated>2010-05-16T07:41:39.500-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vinyl"/><category scheme="http://www.blogger.com/atom/ns#" term="사진"/><title type='text'>vinyl 우리 팀원들</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;나, 성진, 용욱.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZMSfNxV3nm7gWGFcN3HTPlrZpHUhp3RS87myPDjytgXkFt3Fx_E1Ag1Nb5JBqyhCdMx-DWPANn0l79AnrWWOgkHmBiJuh2LfqqHqqfRO58XsBnPFU3xoeskZNivQDt1N7gyiLgJ8nRJxA/s1600/IMG027.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZMSfNxV3nm7gWGFcN3HTPlrZpHUhp3RS87myPDjytgXkFt3Fx_E1Ag1Nb5JBqyhCdMx-DWPANn0l79AnrWWOgkHmBiJuh2LfqqHqqfRO58XsBnPFU3xoeskZNivQDt1N7gyiLgJ8nRJxA/s400/IMG027.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: auto;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjow-LiXv_VVf7MulCNBh-0WjSSf4etOLKLHVH-_5VZnY45qRhRbUTQmp99Umrtp2gAnyssLHeblOxq6LdaYYcLSbWqwX9GU3096sQGhyphenhyphentrFXlIZS6WDhmD_V51Vr-ewo08A_4AOvcz3doH/s1600/IMG030.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjow-LiXv_VVf7MulCNBh-0WjSSf4etOLKLHVH-_5VZnY45qRhRbUTQmp99Umrtp2gAnyssLHeblOxq6LdaYYcLSbWqwX9GU3096sQGhyphenhyphentrFXlIZS6WDhmD_V51Vr-ewo08A_4AOvcz3doH/s400/IMG030.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;vertical-align: top;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDIK7J4X4IjbpJ1OWBcUeyJE71UlE2VNeU9ysRU53w4YcqJjMKnwkd4twPslseG1DX3jIzsjfksHSpCIThrQzm4OVrhaSx4V2b82weYWCB6ezSbXa_2Fa2VW_Y2it-WVf2Ftpi9ZPus0MX/s1600/IMG031.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDIK7J4X4IjbpJ1OWBcUeyJE71UlE2VNeU9ysRU53w4YcqJjMKnwkd4twPslseG1DX3jIzsjfksHSpCIThrQzm4OVrhaSx4V2b82weYWCB6ezSbXa_2Fa2VW_Y2it-WVf2Ftpi9ZPus0MX/s400/IMG031.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;카메라 버튼 누르라고&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/2138444979940517558/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/2138444979940517558' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/2138444979940517558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/2138444979940517558'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/05/vinyl.html' title='vinyl 우리 팀원들'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZMSfNxV3nm7gWGFcN3HTPlrZpHUhp3RS87myPDjytgXkFt3Fx_E1Ag1Nb5JBqyhCdMx-DWPANn0l79AnrWWOgkHmBiJuh2LfqqHqqfRO58XsBnPFU3xoeskZNivQDt1N7gyiLgJ8nRJxA/s72-c/IMG027.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-969935138893036617</id><published>2010-04-13T23:21:00.000-07:00</published><updated>2010-04-13T23:40:04.278-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Model"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby on Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="SQLServer"/><title type='text'>Ruby on Rails : MS SQLSERVER 연동하기</title><content type='html'>Rails 와 SQL Server 를 연동하는건 꽤 힘든 작업이었다. ruby 에 심어주어야하는 odbc 드라이버에는 버전 문제가 있었고, winxp 와 ubuntu 환경에서 DSN(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a6a6a6; font-family: &#39;Lucida Grande&#39;, Arial, Verdana, sans-serif; font-size: 12px; line-height: 15px;&quot;&gt;Data Source Name&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: Verdana; font-size: medium; line-height: normal;&quot;&gt;) 을 생성하는 방법을 익히는데도 시간이 걸렸고, 이를 database.yml 에 작성하는데도 혼선이 있었다.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
다행히 구글링을 통해 여러 블로거들이 제시하는 방법을 적용하며 해결할 수 있었다. 이 글에서는 내가 경험하고 맞딱드린 문제들과 해결방법을 기록하고자 한다. 전체 과정을 상세히 기록하기엔 너무 양이 많기에, 블로그 링크를 걸어두어 그곳의 내용을 자세히 살펴보아야 할것이다.&lt;br /&gt;
&lt;br /&gt;
본 포스팅을 실행한 환경은 다음과 같다.&lt;br /&gt;
&lt;br /&gt;
os : Ubuntu Karmic Koala,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;Windows XP Service Pack 3&lt;br /&gt;
ruby : 1.8.7 version&lt;br /&gt;
rails : 2.3.5 version&lt;br /&gt;
&lt;br /&gt;
우선, windows xp 환경부터 보자. 윈도우 환경은 꽤 간단한 편이다.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Windows XP 에서 설치하기&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. ruby용 odbc 드라이버 받기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.ch-werner.de/rubyodbc/&quot;&gt;http://www.ch-werner.de/rubyodbc/&lt;/a&gt; 에서&amp;nbsp;1.8용 i386-msvcrt-ruby-odbc.zip 파일을 다운받자. 링크된 페이지에는 다음과 같은 내용이 있다.&lt;br /&gt;
&lt;hr /&gt;&lt;div style=&quot;background: white; margin: 0px; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;For Win32 operating systems DLLs of 0.997 are available in i386-msvcrt-ruby-odbc.zip. It contains&amp;nbsp;the files &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;odbc.so&lt;/span&gt; and &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;odbc_utf8.so&lt;/span&gt; which need to be copied into the &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: orange;&quot;&gt;.../ruby/1.8/i386-msvcrt&lt;/span&gt;&amp;nbsp;directory of MSVC based Ruby 1.8 installations.&lt;/div&gt;ruby 1.8 환경에서는 0.997 버전을 다운받아 해당 디렉토리에 압축을 풀라는 내용이다.&lt;br /&gt;
&lt;br /&gt;
이는 최신버전을 사용하지 말라는 얘긴데, ubuntu 에서 설정시에도 낮은 버전의 odbc 파일을 받아야 한다. 이는 ubuntu 설정 과정에서 설명하겠다.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. activerecord-sqlserver-adapter 설치하기&lt;/b&gt;&lt;br /&gt;
우선 gem 을 업데이트 한후 파일을 설치하자.&lt;br /&gt;
&lt;br /&gt;
gem update --system&lt;br /&gt;
gem install activerecord-sqlserver-adapter&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3. DSN 생성하고, odbc 에 연결하기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
윈도우에서는&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #a6a6a6; font-family: &#39;Lucida Grande&#39;, Arial, Verdana, sans-serif; font-size: 12px; line-height: 15px;&quot;&gt;odbcad32.exe &lt;/span&gt;라는 tool 을 이용하여 DSN 을 생성해야 하는데,&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.truthsolutions.com/sql/odbc/creating_a_new_odbc_dsn.htm&quot;&gt;http://www.truthsolutions.com/sql/odbc/creating_a_new_odbc_dsn.htm&lt;/a&gt;&amp;nbsp;페이지에 나온 방법대로 한단계씩 수행하면 된다.&lt;br /&gt;
&lt;br /&gt;
참고로 위 링크 페이지는 windows server2000 에서 예제를 실행하는데, xp 에서는 제어판 &amp;gt; 관리도구 &amp;gt; 데이터 원본(ODBC) 로 프로그램을 실행하면 된다.&lt;br /&gt;
&lt;b&gt;4. database.yml 에 명시하기&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;&lt;div style=&quot;background: white; margin: 0px; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;development:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;adapter: sqlserver&lt;br /&gt;
&amp;nbsp;&amp;nbsp;mode: odbc&lt;br /&gt;
&amp;nbsp;&amp;nbsp;database: databasename&lt;br /&gt;
&amp;nbsp;&amp;nbsp;username: yourid&lt;br /&gt;
&amp;nbsp;&amp;nbsp;password: yourpassword&lt;br /&gt;
&amp;nbsp;&amp;nbsp;dsn: &lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: orange;&quot;&gt;dsnname&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;dsn 입력란에는 방금 생성한 DSN 의 이름을 적으면 된다.&lt;br /&gt;
&lt;br /&gt;
위의 단계를 통해 성공적으로 sqlserver 와 연결된 rails 어플을 뛰울 수 있다.&lt;br /&gt;
&lt;br /&gt;
이제, Ubuntu 환경에서 연동하는 법을 알아보자.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Ubuntu 에서 설치하기&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. 필수 패키지 설치하기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; sudo apt-get install unixodbc tdsodbc libodbc-ruby1.8&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. activerecord-sqlserver-adapte 설치하기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; sudo gem install activerecord-sqlserver-adapter&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3. freeTDS 드라이버를 unixODBC 에 인식시키기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; sudo odbcinst -i -d -f /usr/share/tdsodbc/odbcinst.ini&lt;br /&gt;
&lt;br /&gt;
만약, Ubuntu 가 아닌 다른 리눅스 배포판을 사용한다면,&amp;nbsp;&lt;a href=&quot;http://piao-tech.blogspot.com/2008/02/using-activerecord-with-microsoft-sql.html&quot;&gt;http://piao-tech.blogspot.com/2008/02/using-activerecord-with-microsoft-sql.html&lt;/a&gt;&amp;nbsp;에 나온 방법을 이용하면 된다.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;4. DSN 생성후, unixODBC 에 추가하기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; vim mydsn.ini&lt;br /&gt;
&lt;hr /&gt;&lt;div style=&quot;background: white; margin: 0px; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;[mySQL Server]&lt;br /&gt;
Driver = FreeTDS&lt;br /&gt;
Description = My MSSQL Database&lt;br /&gt;
Trace = No&lt;br /&gt;
Server = ipadress_or_hostname&lt;br /&gt;
Port = 1433&lt;br /&gt;
Database = databasename&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; odbcinst -i -s -f mydsn.ini -h&lt;br /&gt;
&lt;br /&gt;
sudo 가 빠진 점에 유의하자. 이렇게 해야 System 전반에 사용되는 것을 방지할 수 있다. &lt;br /&gt;
&lt;br /&gt;
unixODBC 에 추가되었는지 테스트 해보자.&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; isql -v &quot;mySQL Server&quot; uid upassword&lt;br /&gt;
+---------------------------------------+&lt;br /&gt;
| Connected! &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&lt;br /&gt;
| &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;br /&gt;
| sql-statement &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;br /&gt;
| help [tablename] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&lt;br /&gt;
| quit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&lt;br /&gt;
| &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;br /&gt;
+---------------------------------------+&lt;br /&gt;
SQL&amp;gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;위 화면이 뜬다면 성공이다. 간단한 sql 문을 적어 결과를 얻어올 수도 있다.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;5. database.yml 에 명시하기&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;div style=&quot;background: white; margin: 0px; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;development:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;adapter: sqlserver&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;mode: odbc&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;database: databasename&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;username: yourid&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;password: yourpassword&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;dsn:&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: orange;&quot;&gt;mySQL Server&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;6. rails 어플리케이션 구동하기&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
모든 설정이 완료되었음에도,&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;INTERN (0) [RubyODBC]Cannot allocate SQLHENV&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;/span&gt;라는 에러메세지가 보인다면, 이는 1단계에서 설치한&amp;nbsp;libodbc-ruby1.8 의 버전문제인데, 이경우 구버전인 0.9995 를 사용해야 한다.&amp;nbsp;http://gehling.dk/2010/02/the-woes-of-libodbc-ruby1-8-and-debian-ubuntu/ 에 이에대한 설명이 나와있다.&lt;br /&gt;
&lt;br /&gt;
우선 기존 libodbc-ruby1.8 을 지우자&lt;br /&gt;
$&amp;gt;&amp;nbsp;sudo apt-get remove libodbc-ruby1.8&lt;br /&gt;
&lt;br /&gt;
http://packages.ubuntu.com/hu/hardy/i386/libodbc-ruby1.8/download 에서 구버전을 다운받는다.&lt;br /&gt;
&lt;br /&gt;
$&amp;gt;&amp;nbsp;wget http://mirrors.kernel.org/ubuntu/pool/universe/libo/libodbc-ruby/libodbc-ruby1.8_0.9995-1_i386.deb&lt;br /&gt;
&lt;br /&gt;
$&amp;gt;&amp;nbsp;sudo dpkg -i libodbc-ruby1.8_0.9995-1_i386.deb&lt;br /&gt;
&lt;br /&gt;
이제 서버를 재시작하면 연결에 성공한 화면을 볼수 있다.&lt;br /&gt;
&lt;br /&gt;
참고 블로그 :&lt;br /&gt;
&lt;a href=&quot;http://piao-tech.blogspot.com/2008/02/using-activerecord-with-microsoft-sql.html&quot;&gt;http://piao-tech.blogspot.com/2008/02/using-activerecord-with-microsoft-sql.html&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://gehling.dk/2010/02/the-woes-of-libodbc-ruby1-8-and-debian-ubuntu/&quot;&gt;http://gehling.dk/2010/02/the-woes-of-libodbc-ruby1-8-and-debian-ubuntu/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/969935138893036617/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/969935138893036617' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/969935138893036617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/969935138893036617'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/04/ruby-on-rails-ms-sqlserver.html' title='Ruby on Rails : MS SQLSERVER 연동하기'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-4138582575570163158</id><published>2010-03-31T08:38:00.000-07:00</published><updated>2010-04-11T18:49:14.892-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Phusion Passenger"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby on Rails"/><title type='text'>Ruby on Rails : Phusion Passenger 설치하기</title><content type='html'>Phusion Passenger 설치과정을 간단하게 기록하려한다. 본 예제는 Ubuntu 환경이며, Apache2 가 깔려있다는 전제에서 시작된다. &lt;br /&gt;
&lt;br /&gt;
os : Ubuntu 9.10 Karmic Koala&lt;br /&gt;
ruby : 1.8 version&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;&amp;gt; sudo gem install passenger&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
만약, &lt;br /&gt;
Error installing passenger &lt;br /&gt;
Failed to build gem native extension&lt;br /&gt;
&lt;br /&gt;
위 메세지가 보인다면, &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;&amp;gt; sudo apt-get install ruby1.8-dev&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
를 설치해주면 된다. &lt;br /&gt;
&lt;br /&gt;
이제 다시 passenger 를 설치해보자. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;&amp;gt; sudo gem install passenger&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Apache2 관련 passenger 모듈 설치하기&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;&amp;gt; sudo passenger-install-apache2-module&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
설치과정은 아래 단계를 거치며 진행된다. enter 를 치며, 다음 단계로 진행하면 된다. &lt;br /&gt;
&lt;br /&gt;
step 1.&lt;br /&gt;
&lt;div style=&quot;background: black; color: white; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;Welcome to the Phusion Passenger Apache 2 module installer, v2.2.11.&lt;br /&gt;
&lt;br /&gt;
This installer will guide you through the entire installation process. It&lt;br /&gt;
shouldn&#39;t take more than 3 minutes in total.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s what you can expect from the installation process:&lt;br /&gt;
&lt;br /&gt;
1. The Apache 2 module will be installed for you.&lt;br /&gt;
2. You&#39;ll learn how to configure Apache.&lt;br /&gt;
3. You&#39;ll learn how to deploy a Ruby on Rails application.&lt;br /&gt;
&lt;br /&gt;
Don&#39;t worry if anything goes wrong. This installer will advise you on how to&lt;br /&gt;
solve any problems.&lt;br /&gt;
&lt;br /&gt;
Press Enter to continue, or Ctrl-C to abort.&lt;/div&gt;&lt;br /&gt;
step2.&lt;br /&gt;
&lt;div style=&quot;background: black; color: white; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;Checking for required software...&lt;br /&gt;
&lt;br /&gt;
* GNU C++ compiler... not found&lt;br /&gt;
&lt;br /&gt;
* Ruby development headers... found&lt;br /&gt;
&lt;br /&gt;
* OpenSSL support for Ruby... found&lt;br /&gt;
&lt;br /&gt;
* RubyGems... found&lt;br /&gt;
&lt;br /&gt;
* Rake... found at /usr/bin/rake&lt;br /&gt;
&lt;br /&gt;
* rack... found&lt;br /&gt;
&lt;br /&gt;
* Apache 2... found at /usr/sbin/apache2&lt;br /&gt;
&lt;br /&gt;
* Apache 2 development headers... not found&lt;br /&gt;
&lt;br /&gt;
* Apache Portable Runtime (APR) development headers... not found&lt;br /&gt;
&lt;br /&gt;
* Apache Portable Runtime Utility (APU) development headers... not found&lt;br /&gt;
&lt;br /&gt;
Some required software is not installed.&lt;br /&gt;
&lt;br /&gt;
But don&#39;t worry, this installer will tell you how to install them.&lt;br /&gt;
&lt;br /&gt;
Press Enter to continue, or Ctrl-C to abort.&lt;/div&gt;&lt;br /&gt;
자기 환경에 설치되어 있지 않은 프로그램에 대한 정보를 친절하게 보여준다.&amp;nbsp; Enter 를 치면 다음단계에서 설치방법에 대해 친절하게 설명해준다. &lt;br /&gt;
&lt;br /&gt;
step 3.&lt;br /&gt;
&lt;div style=&quot;background: black; color: white; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;Installation instructions for required software&lt;br /&gt;
&lt;br /&gt;
* To install GNU C++ compiler:&lt;br /&gt;
&lt;br /&gt;
Please run apt-get install build-essential as root.&lt;br /&gt;
&lt;br /&gt;
* To install Apache 2 development headers:&lt;br /&gt;
&lt;br /&gt;
Please run apt-get install apache2-prefork-dev as root.&lt;br /&gt;
&lt;br /&gt;
* To install Apache Portable Runtime (APR) development headers:&lt;br /&gt;
&lt;br /&gt;
Please run apt-get install libapr1-dev as root.&lt;br /&gt;
&lt;br /&gt;
* To install Apache Portable Runtime Utility (APU) development headers:&lt;br /&gt;
&lt;br /&gt;
Please run apt-get install libaprutil1-dev as root.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If the aforementioned instructions didn&#39;t solve your problem, then please take&lt;br /&gt;
&lt;br /&gt;
a look at the Users Guide:&lt;br /&gt;
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/doc/Users guide Apache.html&lt;/div&gt;&lt;br /&gt;
위의 메세지대로 하나씩 설치를 한후, 다시 &lt;strong&gt;&lt;span style=&quot;font-size: large;&quot;&gt;sudo passenger-install-apache2-module&lt;/span&gt;&lt;/strong&gt; 명령을 실행하자.&lt;br /&gt;
&lt;br /&gt;
step 4.&lt;br /&gt;
&lt;div style=&quot;background: black; color: white; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;The Apache 2 module was successfully installed. &lt;br /&gt;
&lt;br /&gt;
Please edit your Apache configuration file, and add these lines:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: yellow; color: red;&quot;&gt;LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: yellow; color: red;&quot;&gt;PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: yellow; color: red;&quot;&gt;PassengerRuby /usr/bin/ruby1.8&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
After you restart Apache, you are ready to deploy any number of Ruby on Rails&lt;br /&gt;
applications on Apache, without any further Ruby on Rails-specific&lt;br /&gt;
&lt;br /&gt;
configuration!&lt;br /&gt;
&lt;br /&gt;
Press ENTER to continue.&lt;/div&gt;&lt;br /&gt;
성공이다. 바탕색이 칠해진 부분은 나중에 apache 설정에 넣어야할 부분임으로 복사해두자. &lt;br /&gt;
&lt;br /&gt;
step 5.&lt;br /&gt;
&lt;div style=&quot;background: black; color: white; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;Deploying a Ruby on Rails application: an example&lt;br /&gt;
&lt;br /&gt;
Suppose you have a Rails application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;virtualhost *:80=&quot;&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ServerName www.yourhost.com&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; DocumentRoot /somewhere/public # &amp;lt;-- be sure to point to &#39;public&#39;!&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;directory public=&quot;&quot; somewhere=&quot;&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AllowOverride all # &amp;lt;-- relax Apache security settings&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Options -MultiViews # &amp;lt;-- MultiViews must be turned off&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;/directory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/virtualhost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And that&#39;s it! You may also want to check the Users Guide for security and&lt;br /&gt;
&lt;br /&gt;
optimization tips, troubleshooting and other useful information: &lt;br /&gt;
&lt;br /&gt;
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/doc/Users guide Apache.html&lt;/div&gt;&lt;br /&gt;
마지막 단계에서는 apache 의 virtual host 설정에 관한 예제도 보여준다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
자기 환경에서 Apache Configure 파일을 찾는 방법은 다음과 같다. &lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;&amp;gt; apache2ctl -V | grep SERVER_CONFIG_FILE&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;output&amp;gt; -D SERVER_CONFIG_FILE=&quot;/etc/apache2/apache2.conf&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
표시된 경로에 있는 파일을 열고(이때, 반드시 sudo 를 입력하여 root 계정으로 편집해야한다),&lt;br /&gt;
&lt;br /&gt;
Phusion Passenger 설치과정에서 복사한 문구를 파일 끝에 넣는다. &lt;br /&gt;
&lt;br /&gt;
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so&lt;br /&gt;
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11&lt;br /&gt;
PassengerRuby /usr/bin/ruby1.8&lt;br /&gt;
&lt;br /&gt;
이제 virtualhost 설정을 해주자. &lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;&amp;gt; sudo vim /etc/apache2/sites-available/default&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
파일에 virtualhost 설정해준다 &lt;br /&gt;
&lt;hr /&gt;&lt;div style=&quot;background: white; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;&quot;&gt;&amp;lt;virtualhost *:80=&quot;&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ServerName www.yourhost.com&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; DocumentRoot /somewhere/public&amp;nbsp; # &amp;lt;-- be sure to point to &#39;public&#39;!&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;directory /somewhere/public &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AllowOverride all&amp;nbsp;&amp;nbsp; # &amp;lt;-- relax Apache security settings&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Options -MultiViews # &amp;lt;-- MultiViews must be turned off&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;/directory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/virtualhost&amp;gt;&lt;/div&gt;&lt;br /&gt;
DocumentRoot 선언에&amp;nbsp;rails 어플리케이션의 public 폴더를 명시하는 점에 주목하자. &lt;br /&gt;
참고로, # 주석은 실제 입력시 빼야 문법오류가 안뜬다&lt;br /&gt;
&lt;br /&gt;
설정이 완료되었으면, &amp;nbsp;apache 를 재시작하자. &lt;br /&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&amp;gt;&amp;nbsp;sudo /etc/init.d/apache2 restart&lt;/span&gt;&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
이제 &lt;a href=&quot;http://localhost/&quot;&gt;http://localhost/&lt;/a&gt; 로 접속했을 때, rails 어플리케이션이 생성된 폴더가 root 로 잡히는걸 확인할 수 있다.</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/4138582575570163158/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/4138582575570163158' title='2개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4138582575570163158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/4138582575570163158'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/03/ruby-on-rails-phusion-passenger.html' title='Ruby on Rails : Phusion Passenger 설치하기'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-8118479180180172167</id><published>2010-03-26T00:11:00.000-07:00</published><updated>2010-04-07T19:16:39.970-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="404"/><category scheme="http://www.blogger.com/atom/ns#" term="500"/><category scheme="http://www.blogger.com/atom/ns#" term="Controller"/><category scheme="http://www.blogger.com/atom/ns#" term="Exception"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby on Rails"/><title type='text'>Ruby on Rails : Action Controller 예외처리(404, 500) 다루기</title><content type='html'>사용자가 브라우저에 존재하지 않는 경로를 요청하거나, 혹은 잘못된 ID값을 get 방식으로 전달할 때 Rails 는 exception 을 일으킨다. Rails API의 ActionController::Rescue 모듈에 관한 설명에는 다음과 같이 나와있다. &lt;br /&gt;
&lt;hr /&gt;&lt;div style=&quot;background: white; margin: 0px; padding-bottom: 8px; padding-left: 8px; padding-right: 8px; padding-top: 8px;&quot;&gt;Actions that fail to perform as expected throw &lt;span style=&quot;color: orange;&quot;&gt;exceptions.&lt;/span&gt; These exceptions can either be rescued for the public view (with a nice user-friendly explanation) or for the developers view (with tons of debugging information). The developers view is already implemented by the Action Controller, but the public view should be tailored to your specific application. &lt;br /&gt;
&lt;br /&gt;
The default behavior for public exceptions is to render a static html file with the name of the error code thrown. If no such file exists, an empty response is sent with the correct status code. &lt;br /&gt;
&lt;br /&gt;
You can &lt;strong style=&quot;color: blue;&quot;&gt;override&lt;/strong&gt; what constitutes a local request by overriding the local_request? method in your own controller. Custom rescue behavior is achieved by overriding &lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;the rescue_action_in_public&lt;/span&gt; and &lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;rescue_action_locally&lt;/span&gt; methods. &lt;/div&gt;&lt;br /&gt;
위의 설명대로, rescue_action_in_public 와 rescue_action_locally 함수를 오버라이딩 함으로써 잘못수행된 요청에 대한 처리를 할수 있다. &lt;br /&gt;
rescue_action 메서드 명뒤에 붙은 public 과 local 은 어떤 차이가 있을까? 잘못된 수행에 의해 exception 이 발생할때, Rails 는 local_request? 함수를 통해 먼저 이 exception이 localhost 에서 발생했는지를 체크한다. 만약, true 일 경우, rescue_action_locally 를 호출하며 rescue_action_public 은 호출하지 않는다.&lt;br /&gt;
&lt;br /&gt;
위의 exception 발생환경에 따른 분기는 유용할지도 모르나, 내 경우 모든 경우가 localhost 에서 발생했기에,&amp;nbsp;rescue_action_in_public 을 언제 활용할 수 있는지는 모르겠다.&amp;nbsp;아래의 예제는 두 환경을 동일하게 처리하도록 코딩된 예제이다. &lt;br /&gt;
ApplicationController 에 다음 메서드를 오버라이딩 한다. &lt;br /&gt;
&lt;br /&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 8px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;def rescue_action_in_public(exception) &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; case exception &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ActiveRecord::RecordNotFound, ActionController::RoutingError, ActionController::UnknownController, ActionController::UnknownAction &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #render_404 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; render :file =&amp;gt; &quot;#{RAILS_ROOT}/public/404.html&quot;, :layout =&amp;gt; false, :status =&amp;gt; 404 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #render_500 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; render :file =&amp;gt; &quot;#{RAILS_ROOT}/public/500.html&quot;, :layout =&amp;gt; false, :status =&amp;gt; 500 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;end &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;def rescue_action_locally(exception) &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; rescue_action_in_public(exception) &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/8118479180180172167/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/8118479180180172167' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/8118479180180172167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/8118479180180172167'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/03/ruby-on-rails-action-controller-404-500.html' title='Ruby on Rails : Action Controller 예외처리(404, 500) 다루기'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-6825870322506970474</id><published>2010-03-25T07:27:00.000-07:00</published><updated>2010-03-26T09:19:18.335-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Model"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby on Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="Validation"/><title type='text'>Ruby on Rails : Active Record Validation 메세지 한글화 하기</title><content type='html'>&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;Rails 가 제공하는 Model단의 validation 기능과 사용자 페이지(View)에 메세지를 보여주는 기능은 무척 유용하다. 만약, 가격 필드에 문자값을 넣으면 validates_numericality_of 메서드를 이용하여 검증하면 다음과 같은 메세지를 뿌려준다.
&lt;/p&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 10px;&quot;&gt;
&lt;pre style=&quot;font-size: large;font-family:Courier;&quot;&gt;
&lt;span style=&quot;font-weight:bold;color:red;&quot;&gt;class&lt;/span&gt; Order &amp;lt; ActiveRecord::Base  
  validates_numericality_of &lt;span style=&quot;color:orange;&quot;&gt;:price&lt;/span&gt;
&lt;span style=&quot;font-weight:bold;color:red;&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
--------------------------------------------------------&lt;br/&gt;
&lt;span style=&#39;font-size:x-large;&#39;&gt;&quot;Price is not a number&quot;&lt;/span&gt; &lt;span style=&#39;font-size:normal;&#39;&gt;&lt;== view page 에서 보여지는 메세지.&lt;/span&gt;
&lt;/div&gt;
&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;
위 메세지를 한글화 하려면 옵션을 주면 다음과 같이 보이게 할수 있다.
&lt;/p&gt;




&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 10px;&quot;&gt;
&lt;pre style=&quot;font-size: large;font-family:Courier;&quot;&gt;

&lt;span style=&quot;font-weight:bold;color:red;&quot;&gt;class &lt;/span&gt;Order &amp;lt; ActiveRecord::Base
  validates_numericality_of &lt;span style=&quot;color:orange;&quot;&gt;:price&lt;/span&gt;, :message =&amp;gt; &quot;항목은 숫자만 입력가능 합니다.&quot;
&lt;span style=&quot;font-weight:bold;color:red;&quot;&gt;end&lt;/span&gt;

&quot;Price 항목은 숫자만 입력가능 합니다.&quot;
&lt;/pre&gt;
&lt;/div&gt;

&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;문제는 저 Price 이다. 이는 속성의 이름이 default 로 문장의 맨앞에 나와있으며, 이를 바꿀 방법이없다. 그렇기에 아쉽지만 좀더 사용자 친화적인 메세지로 바꾸려면 validates_numericality_of 메서드를 포기하고 직접 만드는 수밖에 없다. 다음처럼 말이다.
&lt;/p&gt;


&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 10px;&quot;&gt;
&lt;pre style=&quot;font-size: large;font-family:Courier;&quot;&gt;
class Order &amp;lt; ActiveRecord::Base
  validate :price_must_be_a_number

  protected

  def price_must_be_a_number
    begin
      Kernel.Float(price)
    rescue ArgumentError, TypeError
      errors.add(&#39;price&#39;, &#39;항목은 숫자만 입력해주세요.&#39;)
    end
  end
end

&lt;/pre&gt;
&lt;/div&gt;

&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;
Kernel.Float 는 값이 float 타입인지를 판별하는 여러 방법중 하나이다. 이 방법이 아닌 다르게 체크해도 상관없다. 한데 문제가 있다. 사용자가 숫자가 아닌 문자열을 입력했을 때, price_must_be_a_number 메서드의 price 속성에 떨어지는값이 0.0인것이다 ! Rails 자체적으로 숫자입력이 필요한곳에 문자입력을 했을때 자동으로 0.0으로바꾸는것이다. 그렇기에 사용자가 문자를 입력해도 위의 validation이 통과되버리게된다.
&lt;/p&gt;
&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;
해결방법을 찾아 며칠 전전긍긍한 끝에 Rails API 에서 해답을 얻을 수 있었다 ! &lt;br/&gt;
http://api.rubyonrails.org/classes/ActiveRecord/Base.html 에 문제를 푸는 열쇠가 담겨있다. 다음과 같은 내용이 있다.
&lt;/p&gt;











&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 10px;&quot;&gt;
 
&lt;span style=&quot;font-weight:bold;color:red;font-size:x-large;&quot;&gt;Accessing attributes before they have been typecasted&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;
&lt;span style=&quot;font-size:normal;&quot;&gt;
Sometimes you want to be able to read the raw attribute data without havingthe column-determined typecast run its course first. That can be done by using the_before_type_cast accessors that all attributeshave. For example, if your Account model has a balance attribute,you can call account.balance_before_type_castoraccount.id_before_type_cast.
&lt;br/&gt;
This is especially useful in validation situations where the user mightsupply a string for an integer field and you want to display the originalstring back in an error message. Accessing the attribute normally wouldtypecast the string to 0, which isn‘t what you want.
&lt;/span&gt;
&lt;/div&gt;


&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;
_before_type_cast 를 통해, 케스팅되기 전의 값을 알수 있는 것이다! 이제 다음과 같이 validation 체크가 가능하다.
&lt;/p&gt;



&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 10px;&quot;&gt;
&lt;pre style=&quot;font-size: large;font-family:Courier;&quot;&gt;
validate :price_must_be_a_number

protected

def price_must_be_a_number
  begin
    Kernel.Float(price_before_type_cast)
  rescue ArgumentError, TypeError
    errors.add(&#39;price&#39;, &#39;가격항목에는 숫자만 입력해주세요.&#39;)
  end
end

&quot;Price 가격항목에는 숫자만 입력해주세요.&quot;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;
자, 이제 한글 validation 메세지를 보여주는 마지막 단계이다. errors.add 함수에는 세개의 인자값을 받는데, 다음처럼 마지막 인자인 option 설정을 통해 메세지에서 Price 부분을 제거할 수 있다.
&lt;/p&gt;


&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; padding: 10px;&quot;&gt;
&lt;pre style=&quot;font-size: large;font-family:Courier;&quot;&gt;
validate :price_must_be_a_number

protected

def price_must_be_a_number

  begin
    Kernel.Float(price_before_type_cast)
  rescue ArgumentError, TypeError
    errors.add(&#39;price&#39;, &#39;가격항목에는 숫자만 입력해주세요.&#39;, {:attribute =&amp;gt; &#39;&#39; })
  end
end

&quot;가격항목에는 숫자만 입력해주세요.&quot;
&lt;/pre&gt;&lt;/div&gt;



&lt;p class=&quot;Apple-style-span&quot; style=&quot;font-size: normal;font-family:Courier;&quot;&gt;
위의 방식을 응용하면 모든 입력폼에 관한 한글 validation 메세지를 사용자들에게 제공해줄 수 있게 된다. :) &lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/6825870322506970474/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/6825870322506970474' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/6825870322506970474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/6825870322506970474'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/03/ruby-on-rails-active-record-validation.html' title='Ruby on Rails : Active Record Validation 메세지 한글화 하기'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1019502425077729251.post-2466664882674790740</id><published>2010-03-24T08:02:00.000-07:00</published><updated>2010-03-25T08:23:45.323-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="has_and_belongs_to_many"/><category scheme="http://www.blogger.com/atom/ns#" term="Model"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby on Rails"/><title type='text'>Ruby on Rails : has_and_belongs_to_many Association 의 마법</title><content type='html'>&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Ruby on rails 에서는 모델간의 관계를 정의하기 위해 &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;has_many , belongs_to 등의&amp;nbsp;관계선언을 하게 된다.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;이 본문에서 쓰고자 하는건 다대다 관계를 나타내는 :has_and_belongs_to_many 에 관해서다. 이 선언을 통해 다대다(N:N) 관계에서 Rails 가 제공하는 놀라운 마법을 경험하게 될것이다. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;menus 와 posts 라는 두 테이블이 있다고 가정하자. 한개의 포스트(post)는 여러 메뉴에 속할 수 있고, 메뉴(menu)는 여러 post 들과 관련되어 있다면, 이 둘의 다대다 관계에 놓이게 된다. 이 두 테이블의 관계를 맺어주기 위해선 이들 사이에 join table 이 필요한데, Rails 의 네이밍 관습을 따르기 위해서&amp;nbsp;menus_posts 라는 이름으로 join table 을 생성해야 한다. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;이제 각 테이블을 나타내는 모델 클래스에서 관계를 맺어주자. &lt;/span&gt;&lt;br /&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; margin: 0px 0px 10px; padding-bottom: 5px; padding-left: 10px; padding-right: 5px; padding-top: 8px;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;strong&gt;class&lt;/strong&gt;&lt;/span&gt; Menu&amp;nbsp;&amp;lt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; has_and_belongs_to_many &lt;span style=&quot;color: orange;&quot;&gt;:posts&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;strong&gt;class&lt;/strong&gt; &lt;span style=&quot;color: black;&quot;&gt;Post&amp;nbsp;&amp;lt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; has_and_belongs_to_many &lt;span style=&quot;color: orange;&quot;&gt;:menus&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;strong&gt;class &lt;/strong&gt;&lt;span style=&quot;color: black;&quot;&gt;MenusPost &amp;lt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &lt;span style=&quot;color: #f9cb9c;&quot;&gt;# 선언없음.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&lt;strong&gt;end&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: black; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;MenusPost 모델에는 아무 설정도 하지 않았으며 또 이 모델 class 를 별도로 생성할 필요도 없는데, 이는 join table 이기에 Menu 와 Post 모델에서의 선언만으로 이 세 테이블의 관계를 Rails 는 이미 인식하고 있기 때문이다. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;자, 이제 Rails 의 마법을 경험해보자. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Post 를 등록할 때, 여러 menu 들을 선택할 수&amp;nbsp;있도록 하기 위해선 일반적으로 입력폼에 각 메뉴들의 값을 checkbox 로 뿌려주어 사용자가 다중 선택할 수 있도록 제공될 것이다. 다음과 같이 말이다. &lt;/span&gt;&lt;br /&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; margin: 0px 0px 10px; padding-bottom: 5px; padding-left: 10px; padding-right: 5px; padding-top: 8px;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&amp;lt;input type=&quot;checkbox&quot; name=&quot;post[menu_id][]&quot; value=&quot;7&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;!-- name 속성값에 &quot;post[menu_id]&quot; 뒤에 반드시 &quot;[]&quot; 를 붙여주어야 폼섭밋시 check 된 값들이 배열문자로 전달된다는 점에 유의하자. --&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;만약 위와 같이 checkbox 를 제공하였다면, 생성(Create)시 menu_id 라는 속성이 존재하지 않는다는 에러메세지를 보게 될것이다. 이는 분명 당연한 결과이다. post 테이블에는 menu_id 라는 필드가 존재하지 않기 때문이다.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;하지만 menu_id 에 s 를 붙여 다음과 같이 checkbox 를 제공하면, &lt;/span&gt;&lt;br /&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px; margin-bottom: 0px;&quot; /&gt;&lt;div style=&quot;background: white; margin: 0px 0px 10px; padding-bottom: 5px; padding-left: 10px; padding-right: 5px; padding-top: 8px;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: large;&quot;&gt;&amp;lt;input type=&#39;checkbox&#39; name=&#39;post[menu_id&lt;span style=&quot;background-color: yellow;&quot;&gt;s&lt;/span&gt;][]&#39; value=&#39;7&#39; /&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Create 가 성공적으로 수행되게 되는데, 여기에 우리가 모르는 Rails 의 마법이 발휘되었기 때문이다. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;menu_id 라는 필드는 존재하지 않기에 에러를 발생시켰는데, menu_ids 라는 필드 역시도&amp;nbsp;존재하지 않음에도&amp;nbsp;Rails 는&amp;nbsp;(다대다 관계에 의해) post 가 여러 개의 menu_id 를 가질 수 있음을 알고 있었기에 에러를 발생시키지 않았다.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;더욱 놀라운 점은, menus_posts Join table 의 내용을 들여다 보면 자동으로 입력된 값을 보게 된다는 것이다.&lt;/span&gt;&lt;br /&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px;&quot; /&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;sql&amp;gt; select * from menus_posts; &lt;br /&gt;
+-----------------------+&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+ menu_id&amp;nbsp; |&amp;nbsp;&amp;nbsp;post_id&amp;nbsp;&amp;nbsp;&amp;nbsp;+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;위 쿼리의 결과에서 post_id 가 1 인 것은 방금 생성한 post 를 가리키고, menu_id 값 7, 8 은 post 생성시 체크한 menu 의 값들이다. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;join talbe 에 값을 입력하는 코드를 넣지 않았음에도 Rails 가 모델의 관계를 인지하여 자동으로 값을 넣어준 것이다!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;자, 그럼 수정(update)시에는 또 어떤 마법을 부리는지 살펴보자. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;수정화면에서 생성시 선택했던 menu checkbox 들을 해제하고 다른 값들로 체크한 후 update 를 하면, Rails 는 자동으로 두가지 일을 수행한다. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;첫째, join table 에서 기존에 입력된 값(post_id 가 1인 레코드)들을 모두 지운다.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;둘쨰, 새로 선택한 값을 입력한다.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;수행후 결과는 다음과 같다.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr style=&quot;background: #ddd; border-bottom: #666 0px dashed; border-left: #666 0px dashed; border-right: #666 0px dashed; border-top: #666 1px dashed; height: 4px;&quot; /&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;sql&amp;gt; select * from&amp;nbsp;menus_posts;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+ menu_id&amp;nbsp; |&amp;nbsp;&amp;nbsp;post_id&amp;nbsp;&amp;nbsp;&amp;nbsp;+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;+-----------------------+&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
어떤가? 놀랍지 않은가?</content><link rel='replies' type='application/atom+xml' href='http://beizix.blogspot.com/feeds/2466664882674790740/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1019502425077729251/2466664882674790740' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/2466664882674790740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1019502425077729251/posts/default/2466664882674790740'/><link rel='alternate' type='text/html' href='http://beizix.blogspot.com/2010/03/ruby-on-rails-hasandbelongstomany.html' title='Ruby on Rails : has_and_belongs_to_many Association 의 마법'/><author><name>목이</name><uri>http://www.blogger.com/profile/01240243187150610091</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://3.bp.blogspot.com/_bKV4D_237io/SPYNBAr2npI/AAAAAAAAAAM/-FBpjGuicz8/S220/youngMok0016(8862).jpg'/></author><thr:total>0</thr:total></entry></feed>