Wicked Gem with cocoon gem 并设计用户模型
Wicked Gem with cocoon gem and devise user model
所以我有一个用 devise
生成的 User
模型,我正在使用 Wicked
gem 给我多种形式的选择,从用户那里获取更多数据,将其存储在用户模型中。
一切正常,但我知道我正在尝试添加另一个用户拥有多个学位的模型。我正在使用 cocoon 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, :Whosebuglink, :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, :Whosebuglink, :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, :Whosebuglink, :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'
评论太长了,期待更新。
您遇到的问题是您提交的表单 不 包含任何 user
参数:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EXN7ts6xPVK8vkC7q6UcNleJJWLUtKmOw41T0qsDqXCrPJ0vIHrB/6xIfpp/o+cXKR47F+6LxUY5LjXlCobKZQ==", "commit"=>"Update User", "id"=>"education"}
这可能是 Wicked
,但根据您对 RegistrationsController
的虚假使用判断,我想这可能与格式等有关:
--
如果您正在更新 current_user
,您应该而不是调用您的 registrations
控制器。那是为了 registrations -- 你应该使用你的 users
controller:
#config/routes.rb
resource :user_steps, path: "user", only: [:show, :update] #-> url.com/user (singular resource)
#app/controllers/user_steps_controller.rb
class UserStepsController < ApplicationController
def show
end
def update
@user = current_user.update user_params
render_wizard @user
end
private
def user_params
params.require(:user).permit(:name, :middlename, :lastname, :avatar, :aboutMe, :twitterlink, :githublink, :Whosebuglink, :mediumlink, :dribblerlink, degrees_attributes: [:id, :degreeName, :university, :level, :done, :_destroy])
end
end
这只是控制器;您需要查看 form
是如何呈现和传递的。
如果您使用上述代码发送数据,您需要提取 form
HTML 并展示 Wicked
如何使用它。
您需要在 app/views/users/show.html.erb
中查找表格才能显示,不是 /app/views/registrations
所以我有一个用 devise
生成的 User
模型,我正在使用 Wicked
gem 给我多种形式的选择,从用户那里获取更多数据,将其存储在用户模型中。
一切正常,但我知道我正在尝试添加另一个用户拥有多个学位的模型。我正在使用 cocoon 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, :Whosebuglink, :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, :Whosebuglink, :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, :Whosebuglink, :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'
评论太长了,期待更新。
您遇到的问题是您提交的表单 不 包含任何 user
参数:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"EXN7ts6xPVK8vkC7q6UcNleJJWLUtKmOw41T0qsDqXCrPJ0vIHrB/6xIfpp/o+cXKR47F+6LxUY5LjXlCobKZQ==", "commit"=>"Update User", "id"=>"education"}
这可能是 Wicked
,但根据您对 RegistrationsController
的虚假使用判断,我想这可能与格式等有关:
--
如果您正在更新 current_user
,您应该而不是调用您的 registrations
控制器。那是为了 registrations -- 你应该使用你的 users
controller:
#config/routes.rb
resource :user_steps, path: "user", only: [:show, :update] #-> url.com/user (singular resource)
#app/controllers/user_steps_controller.rb
class UserStepsController < ApplicationController
def show
end
def update
@user = current_user.update user_params
render_wizard @user
end
private
def user_params
params.require(:user).permit(:name, :middlename, :lastname, :avatar, :aboutMe, :twitterlink, :githublink, :Whosebuglink, :mediumlink, :dribblerlink, degrees_attributes: [:id, :degreeName, :university, :level, :done, :_destroy])
end
end
这只是控制器;您需要查看 form
是如何呈现和传递的。
如果您使用上述代码发送数据,您需要提取 form
HTML 并展示 Wicked
如何使用它。
您需要在 app/views/users/show.html.erb
中查找表格才能显示,不是 /app/views/registrations