db Table Column 지원 목록







기본적으로 SQL의 목록을 따른다.



:String

짧은 문자열. 제목이나 태그로 사용.



:Text:

긴 문자열. html의 text_area에 적합.



:Integer

숫자



:Decimal

정밀한 소수. 부동소수점을 정확하게 제공해준다.



:Boolean

true, false만 저장함.



:Binray

사진이나 영상을 원본 그대로 보존할때 사용.



:Date, :Time, :DateTime

날짜와 시간을 저장할때 사용.








Rails 4버전과 PostgreSQL을 사용한다면 이것도 가능


  • :hstore
  • :array
  • :cidr_address
  • :ip_address
  • :mac_address




참조 :

https://stackoverflow.com/questions/11889048/is-there-documentation-for-the-rails-column-types

https://stackoverflow.com/questions/3260345/list-of-rails-model-types






REST 란?


REST는 REpresentational State Transfer 의 줄임말이다.


JSON(JavaScript Object Notation) 와는 다른, 네트워크에서 리소스를 어떻게 표기하고 정의하는지를 정하는 아키텍쳐중 하나이다.

리소스는 우리가 페이지에서 표기하거나 처리하고 싶은 모든 데이터를 의미한다.


REST 아키텍쳐는 Http 의 네가지 메소드(GET, PUT, PUSH, DELETE)를 기반으로 한 각종 유니크한 명령어를 문자로 제공해준다.

예를 들어 Rails에서 articles 이라는 테이블에서 새로운 작성페이지를 'GET'으로 불러오고 싶으면: 


http://mypage/articles/new


이렇게 쓴다. 물론 new 라는 메소드는 컨드롤러에서 정의가 되어있어야 한다.




더 자세한 정의는 여기에서 찾아볼수 있다.













RESTful URL


Rails에서 REST로 제공되는 url을 알아내는 가장 간단한 방법은 Bash 에서


1
$ rake routes
cs


를 치면 된다. 그러면 REST와 관련된 리소스들의 url들이 자동으로 뜬다.



1
2
3
4
5
6
7
8
9
10
11
        Prefix Verb   URI Pattern               Controller#Action
articles_index GET    /articles/index(.:format) articles#index
  new_articles GET    /articles/new(.:format)   articles#new
 edit_articles GET    /articles/edit(.:format)  articles#edit
      articles GET    /articles(.:format)       articles#show
               PATCH  /articles(.:format)       articles#update
               PUT    /articles(.:format)       articles#update
               DELETE /articles(.:format)       articles#destroy
               POST   /articles(.:format)       articles#create
          root GET    /                         articles#index
 
cs







또 다른방법으로는 Rails에서 기본적으로 제공하는 Named Helper들이 있다.


HTTP VerbPathController#ActionNamed Helper
GET/admin/articlesarticles#indexarticles_path
GET/admin/articles/newarticles#newnew_article_path
POST/admin/articlesarticles#createarticles_path
GET/admin/articles/:idarticles#showarticle_path(:id)
GET/admin/articles/:id/editarticles#editedit_article_path(:id)
PATCH/PUT/admin/articles/:idarticles#updatearticle_path(:id)
DELETE/admin/articles/:idarticles#destroyarticle_path(:id)



Named Helper를 url처럼 사용하면 된다. 여기에서 리소스 이름은 자기가 쓰고 싶은것으로 변경하면 된다














참조: 

http://guides.rubyonrails.org/routing.html


http://www.service-architecture.com/articles/web-services/representational_state_transfer_rest.html


https://www.slideshare.net/rmaclean/json-and-rest


http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm



루비온레일즈는 많은 자동화 기능들을 제공하지만 이 기능들을 제대로 쓰려면 관례를 지키는것이 좋다.


Convention over Configuration.




-이름 짓기


변수: 모든 변수의 이름의 첫글자는 소문자로 시작해야 된다. 그리고 띄어쓰는 대신에 언더스코어(_)를 사용한다. 

Java에서 많이 쓰는 캐멀케이스(i.e. myVariable)는 사용하지 않도록 한다.


예시) my_variable, score, 등...




클래스와 모듈: 첫글자와 띄어쓰기에서 모두 대문자를 사용한다.


예시) VisitClass, CreateThisItem, 등...




데이터베이스 테이블(Table): 모두 소문자로 쓰고 띄어쓰기에선 언더스코어(_)를 사용한다. 

그리고 모든 이름은 복수형(Plural)으로 써야한다.


예시) order_items, articles




모델(M): 클래스와 똑같은 방식으로 쓰고, 테이블 이름의 단수형(Singular)으로 쓴다.


예시) OrderItem, Article




컨트롤러(C): 모델과 비슷하지만 복수형으로 적는다.


예시) OrderItemsConroller










+ Recent posts