我想在表演中呈现一个表格。
我知道错误不是来自我忘记创建的路径或文件夹,因为部分没有显示,即使在application.html.erb文件中也没有显示,而共享文件夹中的另外两个部分显示在application.html.erb中。
这是我的乔木:
├── views
│ ├── contact
│ └── devise
└── layout
| └── application.html.erb
└── pages
└── projects
|
|
└──shared
| └── _contactform.html.erb <----- IS NOT SHOWING, not even in application.html.erb
| └── _dropdown.html.erb <----- is showing in: layout --> application.html.erb
| └── _flashes.html.erb <----- is showing in: layout --> application.html.erb
|
└──users
└── index.html.erb
└── show.html.erb <----- contactform should be displayed here这是表单的代码
_contactform.html.erb:
<%= form_for @contact, url: contact_index_path, remote: true do |f| %>
<div class="col-md-6">
<%= f.label :name %></br>
<%= f.text_field :name, required: true, class: "contact-form-text-area" %></br>
<%= f.label :email %></br>
<%= f.text_field :email, required: true, class: "contact-form-text-area" %></br>
<%= f.label :message %></br>
<%= f.text_area :message, rows: 8, cols: 40, required: true, class: "contact-form-text-area",
placeholder: "Send me a message"%></br>
<div class= "hidden">
<%= f.label :nickname %>
<%= f.text_field :nickname, :hint => 'Leave this field blank!' %>
</div>
<%= f.submit 'Send Message', class: 'btn btn-primary' %>
</div>
<% end %>
<div class="col-md-6" id="flash-message">
</div>这是控制器代码
class ContactController < ApplicationController
def index
@contact = Contact.new(params[:home])
end
def create
@contact = Contact.new(params[:home])
@contact.request = request
respond_to do |format|
if @contact.deliver
# re-initialize Contact object for cleared form
@contact = Contact.new
format.html { render 'index'}
format.js { flash.now[:success] = @message = "Thank you for your message. I'll get back to you soon!" }
else
format.html { render 'index' }
format.js { flash.now[:error] = @message = "Message did not send." }
end
end
end
end这是user_controller
class UsersController < ApplicationController
skip_before_action :authenticate_user!, only: [ :index, :show ]
def index
@users = User.all
end
def show
@user = User.find(params[:id])
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
@user.update(user_params)
# Will raise ActiveModel::ForbiddenAttributesError
redirect_to root_path(@user)
end
private
def user_params
params.require(:user).permit(:email, :first_name, :last_name, :description, :facebook, :instagram, :twitter, :linkedin, :phone_number, :country, :birth_date, :job_title, :id)
end
end本地主机给我以下错误消息:
缺少与{:locale=>:en,:formats=>:html,:variants=>[],:handlers=>:raw,:erb,:html,:builder,:ruby,:jbuilder}的部分共享/_contactform。
部分_contactform.html.erb在视图中--> shared。这个共享文件夹中的其他文件也是部分文件,并且非常好地工作和呈现!这是我最不明白的。
我尝试将表单文件移动到另一个文件夹,并在显示中调用它时修改路径,但这仍然是相同的错误消息。
我认为我的路径或什么地方有错误,但当我尝试将application.html.erb中的部分读取为共享文件夹中的其他两个部分时,会显示相同的错误。
发布于 2022-05-02 08:27:49
在users/show.html.erb中呈现部分内容时,请确保不使用_调用它,如下所示:
<%= render 'shared/contactform' %>而非<%= render 'shared/_contactform' %>
https://stackoverflow.com/questions/72079310
复制相似问题