쾌속 개발 주자의 선두 - 레일즈 활용하기 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
코드를 주제별로 분류한다.