我開始使用欄杆部分使用<%=在HTML文件中呈現「Name_of_the_view」%>但由於某種原因不顯示部分視圖。部分視圖在欄杆上不可見
部分已找到但未呈現,所以我得到的僅僅是主視圖中的h1標題。
已經檢查拼寫,設置和所有類型的東西,但不知道什麼是錯的。
這是代碼:
主要HTML文件:
<div class="container">
<h1>Create article</h1>
<%= render "form" %>
</div>
_form文件,其中包含我想渲染(It's同一文件夾內的局部圖,其中主HTML文件是):
<%= form_for @article do |f|%>
<% @article.errors.full_messages.each do |message| %>
<div class="card-panel red">
<span class="white-text"><%= message %></span>
</div>
<% end %>
<div class="form-group">
<label for="title" class="active">Title</label>
<%=f.text_field :title, class:"form-control"%>
</div>
<div class="form-group">
<label for="body" class="active">Body</label>
<%=f.text_area :body, class:"form-control", style:"height:250px"%>
</div>
<%=f.submit "Submit", :class=>"btn btn-primary"%>
</div>
<%end%>
這是控制器:
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render :new
end
end
private
def article_params
params.require(:article).permit(:title,:body)
end
end
在此先感謝。
這就是問題所在。一切都如你所說:這兩個文件都在同一個文件夾中,並且都具有相同的.erb擴展名,所有我都得到它是一個空白部分。 – Guardsoul
添加了有關該問題的其他信息。 – Guardsoul