Giantcarlo
Giantcarlo

Reputation: 23

Rails Unpermitted parameter: :_status

I'm trying to allow the admin to update the user's is_moderator attribute from the index page.

I'm getting this error when I submit the form: Unpermitted parameter: :_status

Here's the code in the form:

<tbody>
    <%@users.each do |user|%>
      <tr>
        <td><%=user.id%></td>
        <td><%=user.username%></td>
        <td><%=user.email%></td>
        <td><%=user.created_at.strftime("%d-%m-%Y") %></td>
        <td> 

          <%= form_for user, :method => :put do |form| %>
            <%= form.radio_button:_status, :is_moderator, :checked => (user.is_moderator) %> 
            <%= form.submit 'Update moderator status'%>
          <% end %>

        </td>
        <td><%= link_to 'Delete User', admin_user_path(user.id), :method => :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %></td>
      </tr>
    <%end%>
  </tbody>

I'm using _status in the form so that the button is already checked if the user is a moderator.

Here are the parameters:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"KBaSldjUe1Ql7ehu5hvz+j76l5qxi9yxQ6FcaCBk/DtE6BbGdMYnaG+Ok8vZVHfEUIsHPC+aZBeJxecyutMtlw==", "user"=>{"_status"=>"is_moderator"}, "commit"=>"Update moderator status", "id"=>"7"}

And here was my latest attempt at a permit method:

def user_params
   params.require(:user).permit(:user => [:_status])
end

I think it's an issue with the user_params method. Any help would be much appreciated :)

Upvotes: 0

Views: 189

Answers (1)

Vitauts Stočka
Vitauts Stočka

Reputation: 191

You have extra level of nesting. Try this

def user_params
   params.require(:user).permit(:_status)
end

Upvotes: 2

Related Questions