Upload
masakuni-kato
View
2.381
Download
6
Embed Size (px)
DESCRIPTION
Citation preview
浜松Rails3道場其の四 View編
Hamamatsurb#7 2011.09.14 @mackato
11年9月14日水曜日
浜松Rails3道場の心得
習うより慣れろ
理論より実用
未知を恐れない
11年9月14日水曜日
実際にRailsアプリを作ってみる
Wiki
全54回位で
11年9月14日水曜日
Wikiの仕様
ページの編集と削除ができる
ページにコメントできる
ページの表示ができる
11年9月14日水曜日
Wikiの仕様
ページの編集履歴が確認できる
ユーザー認証ができる
11年9月14日水曜日
Wikiの仕様
ページの一覧が表示できる
11年9月14日水曜日
Wikiの仕様ページが作成できる
11年9月14日水曜日
今回は其の四View編
参考 - Ruby on Rails Guides
Layouts and Rendering in Railshttp://edgeguides.rubyonrails.org/layouts_and_rendering.html
Rails Form helpershttp://edgeguides.rubyonrails.org/form_helpers.html
参考 - Haml & Sass
#hamlhttp://haml-lang.com/
Sass - Syntactically Awesome Stylesheetshttp://sass-lang.com/
11年9月14日水曜日
開発環境
Ruby Version 1.9.2
Rails Version 3.0.9
.rvmrcrvm ruby-1.9.2-p180@rails-3_0_9
Rake Version 0.9.2
11年9月14日水曜日
サンプルコードの取得GitHubから其の四前のコードを取得
git clone git://github.com/hamamatsu-rb/rails3dojo.git
git checkout -b working 3-controller
前回終了時のタグ作業ブランチ
11年9月14日水曜日
ログイン・ログアウト
11年9月14日水曜日
app/controllers/application_controller.rb
helper_method :current_user def current_user @current_user ||= User.find(session[:user_id])\ if session[:user_id] @current_user rescue ActiveRecord::RecordNotFound => e nil end
11年9月14日水曜日
app/views/layouts/application.html.haml
- if current_user %span#user_name= current_user.name | = link_to "Logout", session_path(session[:user_id]), :method => :delete - else = form_tag sessions_path, :id => "login_form" do %label{:for => "user_name"} Name = text_field_tag :user_name = hidden_field_tag :before_path, request.path = submit_tag "Login"
11年9月14日水曜日
app/views/layouts/application.html.haml
%body = flash_tag
app/halpers/application_helper.rb
def flash_tag unless flash.empty? flash.each do |k, v| return content_tag(:div, v, :class => [k, :flash]) end end end <div class="error flash">Name can't be blank</div>
11年9月14日水曜日
ページの作成・編集
11年9月14日水曜日
app/views/pages/new.html.haml- content_for :title, "New Page"%h1= yield :title%div = render(:partial => 'form', :locals => { :method => :post, :button => "Create" })
app/views/pages/edit.html.haml- content_for :title, "Edit Page"%h1= yield :title%div = render(:partial => 'form', :locals => { :method => :put, :button => "Update" })
11年9月14日水曜日
app/views/pages/_form.html.haml
= form_for @page, :method => method do |f| = f.label :title = f.text_field :title, :class => "full-width" = f.label :body = f.text_area :body, :class => "full-width", :rows => 20 = f.submit button - if method == :put and not @page.title.blank? or = link_to "Back", wiki_page_path(@page.title)
11年9月14日水曜日
ページの表示
11年9月14日水曜日
app/views/pages/show.html.haml- content_for :title, @page.title%h1= yield :title
= markdown(@page.body)%hr{:class => "half-bottom"}%p = page_update_info_tag(@page) - if current_user %br = link_to "Edit", edit_page_path(@page) | = link_to "Delete", page_path(@page), :method => :delete, :confirm => "Are you sure?"
11年9月14日水曜日
RedcarpetRuby library for GitHub Flavored Markdown
Rolling out the Redcarpethttps://github.com/blog/832-rolling-out-the-redcarpet
```rubyputs "Hello World!"````
11年9月14日水曜日
Gemfile
gem "redcarpet"gem "albino"gem "nokogiri"
% pip install pygments
Install Pygments(Python Syntax highlighter)
11年9月14日水曜日
app/helpers/application_helper.rb
def markdown(text) text.gsub!(/\[\[(.+)\]\]/, '[\1](/\1)') options = [:hard_wrap, :filter_html, :autolink, :fenced_code, :gh_blockcode] syntax_highligher(Redcarpet.new(text, *options).to_html).html_safeend def syntax_highligher(html) doc = Nokogiri::HTML(html) doc.search("//pre[@lang]").each do |pre| pre.replace Albino.colorize(pre.text.rstrip, pre[:lang]) end doc.to_send
#272 Markdown with Redcarpet - RailsCastshttp://railscasts.com/episodes/272-markdown-with-redcarpet
11年9月14日水曜日
11年9月14日水曜日
インデントおかしい><
11年9月14日水曜日
コメント・履歴
11年9月14日水曜日
長いんで割愛しますapp/views/pages/show.html.haml の下の方を
読んでください m(_ _)m
11年9月14日水曜日
ページ一覧
11年9月14日水曜日
app/views/pages/index.html.haml
- content_for :title, "Pages"
%h1= yield :title
- @pages.each do |page| %h4= link_to page.title, wiki_page_path(page.title) %p= page_update_info_tag(page)
11年9月14日水曜日
ホームページ
11年9月14日水曜日
app/views/welcome/index.html.haml
- content_for :title, "Welcome"%h1= yield :title
%p Rails3dojo is the ... %br It's made in = link_to "Hamamatsu.rb", "http://hamamatsu-rb.github.com/"
%p At first, please create your = link_to "Home page", wiki_page_path("Home")
11年9月14日水曜日
Wikiの開発は一旦ここまで
git checkout 4-view
作業内容をmasterにマージgit checkout mastergit merge working
作業後のコードはGitHubにありますgit clone git://github.com/hamamatsu-rb/rails3dojo.git
git branch -d working
11年9月14日水曜日
One more thing.
11年9月14日水曜日
既知のバグPageやCommentが消せません><
11年9月14日水曜日
既知のバグPageやCommentが消せません><
ログイン状態で削除をOKしても
11年9月14日水曜日
既知のバグPageやCommentが消せません><
ログイン状態で削除をOKしても
怒られます
11年9月14日水曜日
既知のバグPageやCommentが消せません><
ログイン状態で削除をOKしても
怒られます
しかもセッション消滅
11年9月14日水曜日
Q&A
11年9月14日水曜日
4ヶ月のお付き合い
ありがとうございました。
次回からは単回ものにします。
最後に
11年9月14日水曜日