Home Ask Login Register

Developers Planet

Your answer is one click away!

user5724342 February 2016

Wicked Gem with cocoon gem and devise user model

So I have a User model generated with devise, and I am using Wicked gem to give me multiform option on taking more data from the user and storing it in the user model.

Everything is working fine but know I'm trying to add another model where user has many degree. I am using cocoon gem to allow me to add extra degrees. I am able to go to the multiform page and enter degree information and even add many more degrees to the user, but when i submit the form i get an error;

param is missing or the value is empty: user

Everything else actually gets saved am i can view the user and the rest of the fields entered but non of the degrees.

user model:

has_many :degrees
accepts_nested_attributes_for :degrees, reject_if: :all_blank, allow_destroy: true

degree model:

belongs_to :user

user_steps_controller (this is the wicked gem controller):

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

Registration controller (for devise):

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
   e        

Answers


Richard Peck February 2016

This is too long to comment, I fully expect to update it.


The problem you have is that your form submission does not include any user params:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"EXN7ts6xPVK8vkC7q6UcNleJJWLUtKmOw41T0qsDqXCrPJ0vIHrB/6xIfpp/o+cXKR47F+6LxUY5LjXlCobKZQ==", "commit"=>"Update User", "id"=>"education"}

This might be Wicked, but judging form your spurious use of RegistrationsController, I'd imagine it could be to do with formatting etc:

--

If you're updating your current_user, you should not be invoking your registrations controller. That is for registrations -- you should be using your 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, :stackoverflowlink, :mediumlink, :dribblerlink, degrees_attributes: [:id, :degreeName, :university, :level, :done, :_destroy])
  end
end

This is just the controller; you need to look at how the form is being rendered & passed.

If you're sending data with the above code, you'll want to pull your form HTML and show how Wicked is working with it.

You need to be looking in app/views/users/show.html.erb for the form to display, not /app/views/registrations

Post Status

Asked in February 2016
Viewed 2,093 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life