SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 浜松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
 

Semelhante a 浜松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
 

Mais 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
 

Mais 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編
 

Último

+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@
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+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...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

浜松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