1

I'm attempting to add an option for users to choose to set their user.status to "Public" or "Private." I have this working just fine in my form for users - it saves the status exactly as expected:

     <div class="form-group">
      <%= f.label :status, "Private or Public?" %>
      <%= f.select :status, options_for_select(user_statuses, @user.status) %>
     </div>

In application_helper.rb:

    def user_statuses
      [ ["Private", "Private"], ["Public", "Public"] ]
    end

However, if I add the same form group from above to my devise edit/new views, I can't get the status to save correctly. The user's status remains unchanged/default. Is there something I'm missing?

dstep
  • 135
  • 3
  • 15

1 Answers1

0

I saw your tag contains ruby on rails 4, So I guess you are using rails4, the following answer is based on this guess.

There is a new feature strong parameter in rails 4, you have permit any parameter if you want to mass assignments.

In your case, if you want to save status as well, you have to permit it.

How to ?

In application_controller.rb

add code like

before_filter :configure_permitted_parameters, if: :devise_controller?

protected
    def configure_permitted_parameters
      if resource_class == User
        devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, 
          :password, :password_confirmation, :status) }
      end
    end

hope it helps, if not, please add more information about your app, so we can have further discussion.

Chuanpin Zhu
  • 2,226
  • 1
  • 21
  • 21