当我们在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
页面代码变得简洁很多
分享到:
相关推荐
2. **配置Rails**:在`config/application.rb`文件中,添加`config.generators.template_engine :haml`,这将告诉Rails使用Haml作为默认的模板引擎。 3. **更新脚手架模板**:Rails会查找特定的模板文件来生成新的...
- **模板引擎**: Rails 默认使用 ERB(Embedded Ruby)作为模板引擎,但也可以选择其他的模板引擎如 Haml 或 Slim。 - **前端框架**: 可以集成 Bootstrap 或 Tailwind CSS 等前端框架以快速构建美观的界面。 #### ...
5. **视图和模板引擎**:Rails默认使用ERB(Embedded Ruby)作为视图模板,但也可以选择Haml或Slim。视图负责展示数据,通过`<%= %>`标签将Ruby代码嵌入HTML中,例如显示模型属性`<%= @foodSaver.name %>` 6. **...
4. **数据库管理**:Rails默认使用SQLite数据库,但也可配置为其他如MySQL或PostgreSQL。在“finance-tracker”中,数据库用于存储用户的交易记录、账户信息等财务数据。Rails的ActiveRecord组件简化了数据库操作,...
在 "sinatra_web_app_1" 这个项目中,我们很显然正在探讨如何使用 Sinatra 构建一个基础的 web 应用。 首先,让我们深入了解一下 Sinatra 的核心概念: 1. **路由(Routes)**:Sinatra 的基础是路由系统,它允许...
Sinatra 默认使用 Rack,一个标准的 Ruby Web 服务器接口,可以方便地集成其他中间件,如 session 管理、日志记录和缓存控制。 5. **模型-视图-控制器(MVC)**: 虽然 Sinatra 并不强制 MVC 结构,但可以通过集成 ...