【发布时间】:2016-12-13 03:21:46
【问题描述】:
我正在努力学习 Rails,但由于某种原因,我的视图没有正确呈现!
当我通过网络浏览器在“文档/新”页面上的表单中输入信息时,不会呈现存储在变量中的文本。相反,它实际上是呈现的实例变量。
我正在使用 simple_form gem 以及 haml gem。
编辑:我正在使用 Rails 4.2.5 以及 C9 IDE,如果这有什么不同的话
This is the formatting I want:
This is the formatting I'm getting:
控制器:
class DocsController < ApplicationController
before_action :find_doc, only: [:show, :edit, :update, :destroy]
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
@doc = Doc.find(params[:id])
end
def doc_params
params.require(:doc).permit(:title, :content)
end
结束
_form.html.haml:
= simple_form_for @doc do |f|
= f.input :title
= f.input :content
= f.button :submit
show.html.haml:
%h1= @doc.title
%p= @doc.content
new.html.haml:
%h1 New Doc!
= render 'form'
非常感谢任何帮助!
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 haml