Rails edit.html.erb ArgumentError

rails的新手,我参加了Hartl教程并尝试做出一些改变。 我想允许用户编辑post(我正在调用路由),并在编辑路径时收到此错误:

else object = record.is_a?(Array) ? record.last : record raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object object_name = options[:as] || model_name_from_record_or_class(object).param_key apply_form_for_options!(record, object, options) end 

控制器:

 class RoutesController < ApplicationController # before_action :logged_in_user#, only: [:create, :destroy, :edit, :new] def index @routes = Route.paginate(page: params[:page]) end def create @routes = current_user.routes.build(route_params) if @routes.save flash[:success] = "Route created!" redirect_to '/routes#index' else render 'new' end end def destroy end def show @routes = Route.find(params[:id]) end def edit end def update if @routes.update_attributes(routes_params) flash[:success] = "Route updated" redirect_to @routes else render 'edit' end end private def route_params params.require(:route).permit(:title, :content, :picture) end end 

这是edit.html.erb文件

  

Update your route

Change your image.

谢谢你的帮助!

您必须在控制器的编辑操作中设置@route变量。

 def edit @route = Route.find(params[:id]) end 

应该这样做。