Ruby on rails 这是什么意思?表单中的错误第一个参数不能包含nil或在RoR中为空
我有这个错误,表单中的第一个参数不能包含nil或为空 在下一个代码中,不知道如何解决。我检查了其他类似的问题,但没有运气 我也分享控制器,它似乎是个问题,但仍然不知道如何解决它Ruby on rails 这是什么意思?表单中的错误第一个参数不能包含nil或在RoR中为空,ruby-on-rails,Ruby On Rails,我有这个错误,表单中的第一个参数不能包含nil或为空 在下一个代码中,不知道如何解决。我检查了其他类似的问题,但没有运气 我也分享控制器,它似乎是个问题,但仍然不知道如何解决它 <%= form_for @upload do |f| %> <% if @upload.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@upload.errors.
<%= form_for @upload do |f| %>
<% if @upload.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@upload.errors.count, "error") %> prohibited this document from being saved:</h2>
<ul>
<% @upload.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
禁止保存此文档:
控制器:
这就是我的应用程序中的东西。但我看不出有什么问题
class UploadsController < ApplicationController
before_action :upload_params, only: [:show, :edit, :update, :destroy]
def index
@uploads = Upload.all
end
def show
send_data(@upload.file_contents,
type: @upload.content_type,
filename: @upload.filename)
end
def new
@upload = Upload.new
end
def edit
end
def create
@upload = Upload.new(upload_params)
respond_to do |format|
if @upload.save
format.html { redirect_to upload_path, notice: 'Document was successfully created.' }
format.json { render :show, status: :created, location: @upload }
else
format.html { render :new, notice: 'Wrong file' }
format.json { render json: @upload.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @upload.update(upload_params)
format.html { redirect_to @upload, notice: 'Document was successfully updated.' }
format.json { render :show, status: :ok, location: @upload }
else
format.html { render :edit }
format.json { render json: @upload.errors, status: :unprocessable_entity }
end
end
end
def destroy
@upload.destroy
respond_to do |format|
format.html { redirect_to uploads_url, notice: 'Document was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_upload
@upload = Upload.find(params[:id])
end
def upload_params
params.require(:upload).permit(:file)
end
end
class UploadsController
我想说的是,从错误中可以明显看出这一点。@upload
对象不能是nil
。请确保在呈现此视图(通常在控制器中)之前启动该对象
查看控制器代码,请在执行操作之前将更改为调用set\u upload
在\u操作之前:设置\u上载,仅:[:显示,:编辑,:更新,:销毁]
您需要在控制器上设置@upload=upload.new
,该控制器在哪个视图文件中呈现此表单?谢谢,但我不知道要看什么。如果您有时间,请检查我添加的控制器,请检查我看到的,然后就不见了。谢谢我现在需要知道Rails 4.2.6中这个应用程序记录的替代方案,如果您知道的话,因为在5中您可以编写它,但在4.2.6中我需要更改。你知道这件事吗<代码>类上载<应用程序记录包括csv\u上载程序\u小部件验证:文件大小\u在\u one\u mb下,:csv\u文件\u保存前格式:上载\u本地端
请不要在评论中提出新问题。您的代码在注释中的格式不正确,因此很难阅读和理解您的要求。