Rails:haml视图中的simple_form SyntaxError

时间:2016-04-14 14:21:06

标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-3.2 haml

嗨我有简单形式宝石的问题 我在渲染脚本时遇到错误:

app/views/docs/_form.html.haml:4: syntax error, unexpected ')'
app/views/docs/_form.html.haml:8: syntax error, unexpected '}', expecting keyword_end
app/views/docs/_form.html.haml:8: unterminated string meets end of file
app/views/docs/_form.html.haml:8: syntax error, unexpected end-of-input, expecting keyword_end
app/views/docs/new.html.haml:2:in `_app_views_docs_new_html_haml___3494450644670928784_70227155181520'

view / docs文件 _form.html.haml

= simple_form_for @doc do |f| 
= f.input :title
= f.input :content

= f.button :submit

new.html.haml

= render 'form'

和docs.controller

class DocsController < ApplicationController
  def index
  end

  def show
  end

  def new
    @doc = Doc.new
  end
def create
  @doc = Doc.new(doc_params)
  if @doc.save
    redirect_to @doc
else
  render 'new'
end


end

  def edit
  end

  def update
  end

  def destroy
  end

  private
  def find_doc
  end

  def doc_params
    params.require(:doc).permit(:title, :content)
  end

end

我尝试添加标签&lt; %%&gt;到docs_form.html.haml但它仍无法正常工作

1 个答案:

答案 0 :(得分:0)

看起来你的缩进不正确。对于haml中的循环,您必须缩进其下的代码。这样做:

= simple_form_for @doc do |f|
  = f.input :title
  = f.input :content
  = f.button :submit