【发布时间】:2014-10-19 17:29:29
【问题描述】:
我一直在关注最新版本的 M.Hartl 的 Rails 教程,但在第 7.4.1 章遇到了问题。我创建了一个注册表单,它与用户控制器的新操作相关联。当表单使用有效信息提交时,控制器应重定向到新用户配置文件,但是我会出现以下错误...
我已经包含了 routes.rb 代码以及用户控制器代码。有人可以帮我吗?
当我访问 url ../users/1 页面实际上呈现我的用户,所以我知道用户已经创建并保存到数据库中。不知道是不是redirect_to方法的实现出错了?
任何帮助将不胜感激!
UsersController#create 中的参数错误 参数数量错误(2 比 1)
提取的源代码(第 19 行附近):
private
def _compute_redirect_to_location_with_xhr_referer(options)
store_for_turbolinks begin
if options == :back && request.headers["X-XHR-Referer"]
_compute_redirect_to_location_without_xhr_referer(request.headers["X-XHR-Referer"])
用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(user_params)
if @user.save
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
end
Routes.rb:
Rails.application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
resources :users
end
【问题讨论】:
-
看起来类似于this
-
你能把错误页面中的params内容贴出来吗?
-
使用堆栈跟踪发布完整错误
标签: ruby-on-rails ruby railstutorial.org