用haml写rails中默认的index.html

本文介绍了一个使用HAML重构的Ruby on Rails欢迎页面示例。页面包括社区链接、文档导航及快速开始指南等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当我们在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;

 
页面代码变得简洁很多

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值