`
vivimusing
  • 浏览: 78622 次
  • 性别: Icon_minigender_1
  • 来自: 台州
社区版块
存档分类
最新评论

用haml写rails中默认的index.html

阅读更多

当我们在rails一个工程时,在public文件夹下面有个index.html页面。
我用haml改写一个index.haml
首先我把里面的javascript 和 css 独立的拿出来,放到javascripts/haml.js 和 stylesheets/haml.css中
然后用haml重写这个页面

!!! XML
!!!
%html
  %head
    %meta{'http-equiv' => 'Content-Type', :content => 'text/html',:charset=>"utf-8"}
    %title Ruby on Rails: Welcome aboard
    =javascript_include_tag :defaults
    =javascript_include_tag "haml"
    =stylesheet_link_tag "haml"
      
       

  %body
    #page
      #sidebar
        %ul{:id=>"sidebar-items"}
          %li
            -form_tag("http://www.google.com/search",:id=>"search",:method=>"get") do
              =hidden_field_tag 'hl', 'en'
              =text_field_tag "q","site:rubyonrails.org ",:id=>"search-text"
              =submit_tag "Search"
              the Rails site
         
          %li
            %h3 Join the community
            %ul.links
              %li=link_to "Ruby on Rails","http://www.rubyonrails.org/"
              %li=link_to "Official weblog","http://weblog.rubyonrails.org/"
              %li=link_to "Wiki","http://wiki.rubyonrails.org/"
          %li
            %h3 Browse the documentation
            %ul.links
              %li=link_to "Rails API","http://api.rubyonrails.org/"
              %li=link_to "Ruby standard library","http://stdlib.rubyonrails.org/"
              %li=link_to "Ruby core","http://corelib.rubyonrails.org/"
      #content
        #header
          %h1 Welcome aboard
          %h2 You’re riding Ruby on Rails!
        #about
          %h3=link_to "About your application’s environment","rails/info/properties",:onclick=>"about(); return false"
          #about-content{:style=>"display: none"}
        #getting-started
          %h1 Getting started
          %h2 Here’s how to get rolling:
          %ol
            %li 
              %h2="Use <tt>script/generate</tt> to create your models and controllers"
              %p To see all available options, run it without parameters.
            %li
              %h2 Set up a default route and remove or rename this file
              %p Routes are set up in config/routes.rb.
            %li
              %h2 Create your database
              %p="Run <tt>rake db:migrate</tt> to create your database. If you're not using SQLite (the default), edit <tt>config/database.yml</tt> with your username and password."

               
              
      #footer &nbsp;

 
页面代码变得简洁很多

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics