所以我有一个User
用 生成的模型devise
,我正在使用Wicked
gem 为我提供多格式选项,以从用户那里获取更多数据并将其存储在用户模型中。
一切正常,但我知道我正在尝试添加另一个用户拥有多个学位的模型。我正在使用茧宝石允许我添加额外的degrees
。我可以进入多表单页面并输入学位信息,甚至可以向用户添加更多学位,但是当我提交表单时出现错误;
param is missing or the value is empty: user
其他所有内容实际上都被保存了,我可以查看用户和输入的其他字段,但不是学位。
用户模型:
has_many :degrees
accepts_nested_attributes_for :degrees, reject_if: :all_blank, allow_destroy: true
学位模型:
belongs_to :user
user_steps_controller(这是邪恶的 gem 控制器):
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :personal, :avatar_and_about_yourself, :social, :education
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.update_attributes(user_params)
render_wizard @user
end
private
def user_params
params.require(:user).permit(:name, :middlename, :lastname, :avatar, :aboutMe, :twitterlink, :githublink, :stackoverflowlink, :mediumlink, :dribblerlink, degrees_attributes: [:id, :degreeName, :university, :level, :done, :_destroy])
end
end
注册控制器(用于设计):
class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
# GET /resource/sign_up
def new
super
end
# POST /resource
def create
super
end
# PUT /resource
def update
super
end
protected
# The path used after sign up.
def after_sign_up_path_for(resource)
user_steps_path
end
# The path used after sign up for inactive accounts.
def after_inactive_sign_up_path_for(resource)
user_steps_path
end
def sign_up_params
params.require(:user).permit(:email, :password, :password_confirmation, :name, :middlename, :lastname, :avatar, :aboutMe, :twitterlink, :githublink, :stackoverflowlink, :mediumlink, :dribblerlink, degrees_attributes: [:id, :degreeName, :university, :level, :done, :_destroy])
end
end
我在 user_steps_controller 中遇到错误:
ActionController::ParameterMissing in UserStepsController#update
param is missing or the value is empty: user
并且错误在这一行内:
def user_params
params.require(:user).permit(:name, :middlename, :lastname, :avatar, :aboutMe, :twitterlink, :githublink, :stackoverflowlink, :mediumlink, :dribblerlink, degrees_attributes: [:id, :degreeName, :university, :level, :done, :_destroy])
end
另外,我将如何查看输入的字段,例如,如果我想查看用户名,它是:
<%= @user.name %>
但是我将如何显示每个学位?它只是一个循环吗?
<% @users.degree.each do |degree| %>
终端日志:
Started PATCH "/user_steps/education" for ::1 at 2016-02-09 11:23:29 +0000
Processing by UserStepsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EXN7ts6xPVK8vkC7q6UcNleJJWLUtKmOw41T0qsDqXCrPJ0vIHrB/6xIfpp/o+cXKR47F+6LxUY5LjXlCobKZQ==", "commit"=>"Update User", "id"=>"education"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 16]]
Completed 400 Bad Request in 2ms (ActiveRecord: 0.2ms)
ActionController::ParameterMissing (param is missing or the value is empty: user):
app/controllers/user_steps_controller.rb:20:in `user_params'
app/controllers/user_steps_controller.rb:13:in `update'