ruby-on-rails – 错误:haml语法错误,意外的keyword_ensure,期待$end

已经转换设计从erb到Haml的新会话但是没有用,这是代码

%div.row.show-grid
 %div.span8.offset7
  %h1 Sign in

  - form_for(resource,:as => resource_name,:url => session_path(resource_name)) do |f| 
   %div.clearfix
   = f.label :email 
    %div.input
     = f.email_field :email,:class => 'xlarge',:id => 'admin_email' 
    %div.clearfix       
    = f.label :password 
    %div.input
     = f.password_field :password,:id => 'admin_password' 
     - if devise_mapping.rememberable? 
      %div = f.check_Box :remember_me  
      = f.label :remember_me 
    %div = f.submit "Sign up"

这是最初的erb代码

<div class="row show-grid">
    <div class="span8 offset7">


<div class="page-header">
    <h1>Sign in</h1>
  </div>
<%= form_for(resource,:url => session_path(resource_name)) do |f| %>

  <div class="clearfix">
            <%= f.label :email %>
            <div class="input">
              <%= f.email_field :email,:id => 'admin_email' %>
            </div>
          </div>

   <div class="clearfix">
            <%= f.label :password %>
            <div class="input">
              <%= f.password_field :password,:id => 'admin_password' %>
            </div>
          </div>
            <% if devise_mapping.rememberable? -%>
    <div><%= f.check_Box :remember_me %> <%= f.label :remember_me %></div>
  <% end -%>

          <div><%= f.submit "Sign up" %></div>

<% end %>

解决方法

首先,您可以直接使用.class和#id,它们是%div.class和%div #id的快捷方式

其次,此错误通常在代码的“块”中触发,如:

- if cond
  =# instr

要么

- form_for(options) do |f|
  =# instr

给我们错误线会有所帮助.但是我会说你在其中一个代码块中搞砸了缩进.

编辑

哦,我明白了.你忘了缩进第7行,= f.label:电子邮件.另外,%tag =代码不起作用,你必须嵌套它,或者用%tag =代码来做

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...