我正在按照 hartl 教程构建我的应用程序,但我没有使用 User 作为我的模型,而是使用 Guide。
现在我在第 9.2.1 章链接到 edit_path 时,导致错误:
GuidesController#edit 中的 ActionController::ParameterMissing
并且应用程序跟踪是
app/controllers/guides_controller.rb:42:in
guide_params' app/controllers/guides_controller.rb:29:in
edit'
我的guides_controller.rb 是
class GuidesController < ApplicationController
before_action :signed_in_guide, only: [:edit, :update, :index]
before_action :correct_guide, only: [:edit, :update]
def index
@guides = Guide.all
end
def new
@guide = Guide.new
end
def show
@guide = Guide.find(params[:id])
end
def create
@guide = Guide.new(guide_params)
if @guide.save
# successful
guide_sign_in @guide
flash[:success] = "guide signup success!"
redirect_to @guide
else
flash[:success] = "guide signup failed!"
render 'new'
end
end
def edit
@guide = Guide.find(params[:id])
if @guide.update_attributes(guide_params)
flash[:success] = "Profile updated"
redirect_to @guide
else
render 'edit'
end
end
private
def guide_params
params.require(:guide).permit(:name, :email,
:password, :password_confirmation)
end
def signed_in_guide
unless guide_signed_in?
store_location
redirect_to guidesignin_url, notice: "Please sign in."
end
end
def correct_guide
@guide = Guide.find(params[:id])
redirect_to(root_url) unless current_guide?(@guide)
end
end
我不明白为什么参数会丢失......有人可以帮助我吗?多谢!