달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2008. 4. 23. 20:28

Ruby Programming Tip Ruby2008. 4. 23. 20:28

TextMate Tip


프로젝트를 열기


mate .

. 현재 열려 있는 루비 프로그램 수행하기
cmd+r
  • API Manual 보기
. 포맷팅 설정하기
export RI="--format ansi --width 70"

. 클래스에 대한 정보 보기
ri GC

. 메소드에 대한 정보 보기
ri garbage_collect

. 모든 클래스 보기

ri -c
:
Posted by codetemplate
2008. 4. 11. 23:58

Ruby Programming Ruby2008. 4. 11. 23:58

API Manual 보기

ri GC <-- 클래스
ri garbage_collect <-- method

509 export RI="--format ansi --width 70"
510 ri -c

t1.rb 로딩하기

msmac ~/ruby/chapt-1] irb
>> load "t1.rb"
=> true
>> hello("XXXXX")
Hello XXXXX
=> nil
>> exit

:
Posted by codetemplate
2008. 4. 2. 13:29

rails 팁 Ruby2008. 4. 2. 13:29

1. 모델에 속성 추가할 때

필요한 경우(relationship 추가) model 변경
script/migration mig_name
db/migrate/mig_name 수정
rake db:migrate

:
Posted by codetemplate
2008. 3. 30. 13:38

backlog system을 rails로 개발하기 Ruby2008. 3. 30. 13:38

2008/03/29

프로젝트 생성

msmac ~/ruby> rails backlog

svn에 프로젝트 임포트하기

msmac ~/ruby> svn import backlog http://source.daumcorp.com/private/msbaek/trunk/backlog -m '1 프로젝트 생 성 후'

MakeResourceFul 플러그인 설치

msmac ~/ruby/codetalks] script/plugin install http://svn.hamptoncatlin.com/make_resourceful/trunk
vendor/plugins/make_resourceful 디렉토리에 생성됨

msmac ~/ruby/backlog] svn add vendor/plugins/make_resourceful

msmac ~/ruby/backlog] svn status

msmac ~/ruby/backlog] svn commit -m 'MakeResourceFul 플로그인 설치 후, scaffold 생성 전'
Committed revision 6.

haml 플러그인 설치

msmac ~/ruby/codetalks] sudo gem install haml
msmac ~/ruby/codetalks] haml --rails .

scaffold 생성하기

msmac ~/ruby/backlog] script/generate resourceful_scaffold task type:integer state:integer title:string description:text

이때 주요하게 생성된 파일은 아래와 같다.

app/models/task.rb
app/controllers/tasks_controller.rb
config/routes.rb
db/migrate/001_create_tasks.rb

msmac ~/ruby/backlog] svn commit -m '스캐폴드 생성 후'
Committed revision 7.

:
Posted by codetemplate
2008. 3. 29. 22:52

쾌속 개발 주자의 선두 - 레일즈 활용하기 Ruby2008. 3. 29. 22:52

http://jus1170.tistory.com/4383

svn co svn://rubyforge.org/var/svn/springnote/codetalks@65

1. 프로젝트 생성
msmac ~/ruby] rails codetalks -d sqlite3

1.1 MakeResourceFul 플러그인 설치
msmac ~/ruby/codetalks] script/plugin install http://svn.hamptoncatlin.com/make_resourceful/trunk

1.2 scaffold 생성하기
msmac ~/ruby/codetalks] script/generate resourceful_scaffold code \
> title:string \
> source:text \
> description:tex

1.3 haml 설치
msmac ~/ruby/codetalks] sudo gem install haml

1.4 haml 플러그인 설치
msmac ~/ruby/codetalks] haml --rails .
Haml plugin added to .

http://localhost:3000/codes

blueprintcss 플러그인 설치
script/plugin install http://svn.ariejan.net/plugins/blueprint

이게 잘 안된다.

Ultraviolet을 이용한 코드 문법 강조
http://snippets. aktagon.com/snippets/61-Installing-Ultraviolet-and-Onigurama
$ wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.8.0.tar.gz
$ tar zxvf onig-5.8.0.tar.gz
$ cd onig-5.8.0/
$ ./configure
$ make
$ sudo make install
$ sudo gem install -r ultraviolet --include-dependencies

엑스퀘어드 XHTML 편집기의 적용
msmac ~/ruby/codetalks] script/plugin install svn://rubyforge.org/var/svn/springnote/plugins/xquared

msmac ~/ruby/codetalks] vi app/views/layouts/application.html.haml
%html
%head
%title
= title
= stylesheet_link_tag 'application', 'cobalt', :media => 'screen, projection'
= xquared_include_tag

msmac ~/ruby/codetalks] vi app/views/codes/_form.html.haml
%p
%label{:for => "code_title"} Title:
= f.text_field :title
%p
%label{:for => "code_source"} Source:
= f.text_area :source, :cols => 75, :style => 'display:block'
%p
%label{:for => "code_description"} Description:
= xquared_text_area_tag "code[description]", @code['description']

쓰레드 형식으로 보기
msmac ~/ruby/codetalks] script/plugin install svn://rubyforge.org/var/svn/betternestedset/tags/stable/betternestedset

msmac ~/ruby/codetalks] cat app/models/code.rb class Code < ActiveRecord::Base
acts_as_nested_set
end

msmac ~/ruby/codetalks] script/generate migration AddThreadSupport

msmac ~/ruby/codetalks] vi db/migrate/002_add_thread_support.rb

class AddThreadSupport < ActiveRecord::Migration
def self.up
add_column :codes, :parent_id, :integer
add_column :codes, :lft, :integer, :default => 1
add_column :codes, :rgt, :integer, :default => 2
end

def self.down
remove_column :codes, :parent_id
remove_column :codes, :lft
remove_column :codes, :rgt
end
end

msmac ~/ruby/codetalks] rake db:migrate

msmac ~/ruby/codetalks] vi app/views/codes/show.html.haml

= code_highlight current_object.source
%p.description
= current_object.description

%p
= link_to 'Edit', edit_object_path
|
= link_to 'Destroy', object_path, :confirm => 'Really destroy code?', :method => :delete
|
= link_to 'Back', objects_path
|
= link_to 'Reply', new_object_path + "?parent_id=#{current_object.id}"

%hr/
%h2 Replies
= render :partial => 'code', :collection => current_object.all_children

msmac ~/ruby/codetalks] cat app/controllers/codes_controller.rb
class CodesController < ApplicationController
make_resourceful do
actions :all

before :new do
current_object.title = @parent.title if @parent
end

before :new, :create do
@parent = Code.find(params[:parent_id]) unless params[:parent_id].blank?
end

after :create do
current_object.move_to_child_of(@parent) if @parent
end
end
end

코드를 주제별로 분류한다.

:
Posted by codetemplate
2008. 3. 16. 19:20

Eclipse로 루비 개발하기 Ruby2008. 3. 16. 19:20

http://www.ibm.com/developerworks/kr/library/tutorial/os-eclipse-europa3/index.html

Eclipse로 루비 개발하기
RDT(Ruby Development Tools)

http://updatesite.rubypeople.org/release
ruby perspective

RDT는 루비 코드에 적용되는 기본 기능들을 제공하지만 레일스에 최적화되어 있지는 않다. RDT를 만든 개발자들이 Rails 개발자를 위한 도구를 만든 것이 RadRails이다. RadRails는 이클립스에서 레일스의 기능들에 초점을 맞춰 RDT 기반에서 만들어졌다.

RadRails 설치
Aptana
http://update.aptana.com/install/3.2

설치 후에 Help/Aptana Start Page...
"install"을 클릭하면 Aptana는 이미 설치된 Eclipse 업데이트 시스템을 통해 RadRails 플러그인을 설치한다.

설치 후에 Windows > Open Perspective > Others에서 RadRails perspective로 전환할 수 있다.

1. 레일스 프로젝트 생성하기
File > New > Rails Project 선택
- 프로젝트명에 baseball 입력
- Use default location , Generate Rails application skeleton / Create a Mogrel server 체크
- 만일 Mongrel 서버가 설치되어 있지 않다면 Gems(gem install mongrel)을 통해 설치

2. 데이터베이스 설정하기
config/database.yml 파일을 열어서 아래와 같이 편집

# MySQL (default setup). Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql
# On MacOS X:
# gem install mysql -- --include=/usr/local/lib
# On Windows:
# gem install mysql
# Choose the win32 build.
# Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
database: baseball
username: root
password: password
host: localhost

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: baseball_test
username: root
password:
host: localhost

production:
adapter: mysql
database: baseball_production
username: root
password:
host: localhost

3. Data Perspective 사용하기
Window > Perspective > Data
- 데이터베이스의 테이블을 보여주며, 질의를 실행할 수 있다.
- 데이터베이스 개발 퍼스펙티브와 유사하지만 데이터베이스 설정을 위해 database.yml 파일을 사용한다는 점이 다르다.

4. RadRails와 레이크
4.1 기존 스키마로 작업하기
- RadRails 퍼스펙티브 / Rake Tasks에서 "db:schema:dump"를 선택하고 "Go" 버튼 클릭
- db/schema.rb에 덤프가 생성됨
- db:schema:load를 실행하면 반대로 schema.rb 파일의 내용이 데이터베이스에 반영된다.

4.2 RadRails의 레일스 생성기들
- RadRails 퍼스펙티브 / Generators에서 선택

4.2 모델 생성
- Generators에서 model 선택, 인자로 player로 지정, "Go" 클릭

class Player < ActiveRecord::Base
has_many
:games
end

class
Game < ActiveRecord::Base
belongs_to
:player
end

4.3 스캐폴딩
generator에서 scaffold 선택, player를 인자로 지정, "Go"
같은 방법으로 game에 대한 스캐폴딩도 생성

5. 어플리케이션 테스트하기
- 어플리케이션을 띄우기 위해 서버뷰로 이동해서 서버 스타트

:
Posted by codetemplate
2006. 11. 5. 19:02

Ruby Eclipse Plugin Ruby2006. 11. 5. 19:02

ruby eclipse plugin
http://sourceforge.net/projects/rubyeclipse

IBM Developer's works의 Eclipse용 Ruby Development Tools (RDT) 사용법
http://www-128.ibm.com/developerworks/kr/library/os-rubyeclipse/index.html
:
Posted by codetemplate