SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
View
              Hamamatsurb#7 2011.09.14 @mackato




11   9   14
11   9   14
Wiki

              54


11   9   14
11   9   14
11   9   14
11   9   14
11   9   14
View
                                - Ruby on Rails Guides
              Layouts and Rendering in Rails
              http://edgeguides.rubyonrails.org/layouts_and_rendering.html
              Rails Form helpers
              http://edgeguides.rubyonrails.org/form_helpers.html


                                       - Haml & Sass
              #haml
              http://haml-lang.com/
              Sass - Syntactically Awesome Stylesheets
              http://sass-lang.com/



11   9   14
Version 1.9.2
                           Version 3.0.9
                           Version 0.9.2
              .rvmrc
              rvm ruby-1.9.2-p180@rails-3_0_9


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
                      <div class="error flash">Name can't be blank</div>
          end


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
Ruby library for GitHub Flavored Markdown




                                                    ```ruby
                                                    puts "Hello World!"
                                                    ````




                         Rolling out the Redcarpet
                https://github.com/blog/832-rolling-out-the-redcarpet

11   9   14
Gemfile
     gem "redcarpet"
     gem "albino"
     gem "nokogiri"




     Install Pygments(Python Syntax highlighter)
     % pip install pygments




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_safe
     end

     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_s
     end




                  #272 Markdown with Redcarpet - RailsCasts
                  http://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
git checkout master
                      git merge working
                      git branch -d working



         git clone git://github.com/hamamatsu-rb/rails3dojo.git
         git checkout 4-view


11   9   14
11   9   14
11   9   14
11   9   14
11   9   14
11   9   14
11   9   14
11   9   14

Contenu connexe

Tendances

Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
Albert Jessurum
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
RORLAB
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
Vance Lucas
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2
RORLAB
 

Tendances (20)

[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
 
Desymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus BundlesDesymfony 2011 - Habemus Bundles
Desymfony 2011 - Habemus Bundles
 
A deep dive into Drupal 8 routing
A deep dive into Drupal 8 routingA deep dive into Drupal 8 routing
A deep dive into Drupal 8 routing
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
浜松Rails3道場 其の参 Controller編
浜松Rails3道場 其の参 Controller編浜松Rails3道場 其の参 Controller編
浜松Rails3道場 其の参 Controller編
 
Using a Plone JSON API to interface modern Web Applications
Using a Plone JSON API to interface modern Web ApplicationsUsing a Plone JSON API to interface modern Web Applications
Using a Plone JSON API to interface modern Web Applications
 
.Bash profile
.Bash profile.Bash profile
.Bash profile
 
JSUG - Java Service Enabler by Andreas Hubmer
JSUG - Java Service Enabler by Andreas HubmerJSUG - Java Service Enabler by Andreas Hubmer
JSUG - Java Service Enabler by Andreas Hubmer
 
Charlie Talk - REST
Charlie Talk - RESTCharlie Talk - REST
Charlie Talk - REST
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 
Bake by cake php2.0
Bake by cake php2.0Bake by cake php2.0
Bake by cake php2.0
 
Binary Studio Academy 2016: Laravel Routing
Binary Studio Academy 2016: Laravel Routing Binary Studio Academy 2016: Laravel Routing
Binary Studio Academy 2016: Laravel Routing
 
Laravel 101
Laravel 101Laravel 101
Laravel 101
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2
 
Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworks
 
Rails Routes off the tracks
Rails Routes off the tracksRails Routes off the tracks
Rails Routes off the tracks
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
REST in practice with Symfony2
REST in practice with Symfony2REST in practice with Symfony2
REST in practice with Symfony2
 

Similaire à 浜松Rails3道場 其の四 View編

Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
railsconf
 
Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)
Joao Lucas Santana
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in Rails
Benjamin Vandgrift
 

Similaire à 浜松Rails3道場 其の四 View編 (20)

Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11
 
Statische Websites in Rails 3.1
Statische Websites in Rails 3.1Statische Websites in Rails 3.1
Statische Websites in Rails 3.1
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)Desenvolvimento web com Ruby on Rails (parte 2)
Desenvolvimento web com Ruby on Rails (parte 2)
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in Rails
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 

Plus de Masakuni Kato

スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介
スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介
スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介
Masakuni Kato
 
リーン・スタートアップ のためのテスト
リーン・スタートアップ のためのテストリーン・スタートアップ のためのテスト
リーン・スタートアップ のためのテスト
Masakuni Kato
 
CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5mins
Masakuni Kato
 
浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編 浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編
Masakuni Kato
 

Plus de Masakuni Kato (11)

Hamackathon ideathon 2014.02.22
Hamackathon ideathon 2014.02.22Hamackathon ideathon 2014.02.22
Hamackathon ideathon 2014.02.22
 
RubyMotionでiOS開発
RubyMotionでiOS開発RubyMotionでiOS開発
RubyMotionでiOS開発
 
スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介
スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介
スマートフォンを利用した会員カードシステムサービス「Smaca」のご紹介
 
スターターライセンスではじめるAtlassian開発
スターターライセンスではじめるAtlassian開発スターターライセンスではじめるAtlassian開発
スターターライセンスではじめるAtlassian開発
 
Blogging on jekyll
Blogging on jekyllBlogging on jekyll
Blogging on jekyll
 
Hamamatsu.rb.20111210
Hamamatsu.rb.20111210Hamamatsu.rb.20111210
Hamamatsu.rb.20111210
 
Twitter bootstrap on rails
Twitter bootstrap on railsTwitter bootstrap on rails
Twitter bootstrap on rails
 
リーン・スタートアップ のためのテスト
リーン・スタートアップ のためのテストリーン・スタートアップ のためのテスト
リーン・スタートアップ のためのテスト
 
Start developing Facebook apps in 13 steps
Start developing Facebook apps in 13 stepsStart developing Facebook apps in 13 steps
Start developing Facebook apps in 13 steps
 
CoffeeScript in 5mins
CoffeeScript in 5minsCoffeeScript in 5mins
CoffeeScript in 5mins
 
浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編 浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

浜松Rails3道場 其の四 View編

  • 1. View Hamamatsurb#7 2011.09.14 @mackato 11 9 14
  • 2. 11 9 14
  • 3. Wiki 54 11 9 14
  • 4. 11 9 14
  • 5. 11 9 14
  • 6. 11 9 14
  • 7. 11 9 14
  • 8. View - Ruby on Rails Guides Layouts and Rendering in Rails http://edgeguides.rubyonrails.org/layouts_and_rendering.html Rails Form helpers http://edgeguides.rubyonrails.org/form_helpers.html - Haml & Sass #haml http://haml-lang.com/ Sass - Syntactically Awesome Stylesheets http://sass-lang.com/ 11 9 14
  • 9. Version 1.9.2 Version 3.0.9 Version 0.9.2 .rvmrc rvm ruby-1.9.2-p180@rails-3_0_9 11 9 14
  • 10. GitHub git clone git://github.com/hamamatsu-rb/rails3dojo.git git checkout -b working 3-controller 11 9 14
  • 11. 11 9 14
  • 12. 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
  • 13. 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
  • 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 <div class="error flash">Name can't be blank</div> end 11 9 14
  • 15. 11 9 14
  • 16. 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
  • 17. 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
  • 18. 11 9 14
  • 19. 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
  • 20. Ruby library for GitHub Flavored Markdown ```ruby puts "Hello World!" ```` Rolling out the Redcarpet https://github.com/blog/832-rolling-out-the-redcarpet 11 9 14
  • 21. Gemfile gem "redcarpet" gem "albino" gem "nokogiri" Install Pygments(Python Syntax highlighter) % pip install pygments 11 9 14
  • 22. 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_safe end 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_s end #272 Markdown with Redcarpet - RailsCasts http://railscasts.com/episodes/272-markdown-with-redcarpet 11 9 14
  • 23. 11 9 14
  • 24. 11 9 14
  • 25. 11 9 14
  • 27. 11 9 14
  • 28. 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
  • 29. 11 9 14
  • 30. 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
  • 31. git checkout master git merge working git branch -d working git clone git://github.com/hamamatsu-rb/rails3dojo.git git checkout 4-view 11 9 14
  • 32. 11 9 14
  • 33. 11 9 14
  • 34. 11 9 14
  • 35. 11 9 14
  • 36. 11 9 14
  • 37. 11 9 14
  • 38. 11 9 14