我正在通過學習Rails來擠壓我的方式,但由於某種原因,我的視圖沒有被正確渲染!我的意見不是將輸入的文本呈現爲表格
當我通過網絡瀏覽器將信息輸入到'docs/new'頁面的表單中時,文本不會被存儲在變量中。相反,它實際上是呈現的實例變量。
我使用的是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.ha毫升:
= 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'
任何幫助是非常感謝!
謝謝!它現在解決了! –