Rails: parameter missing in update action -
here's error message:
actioncontroller::parametermissing in userscontroller#update param missing or value empty: user
full error log
actioncontroller::parametermissing (param missing or value empty: user): app/controllers/users_controller.rb:36:in `update_user_params' app/controllers/users_controller.rb:15:in `update'
the error highlights line:
def update_user_params params.require(:user).permit(:role) end
the parameters on error these:
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"nvso53f3pfihoxdthmfcaxgtidaewnxppsgtnzkp/zc=", "admin"=>{"role"=>"user"}, "commit"=>"make user", "id"=>"2"}
here's form i'm using: show.html.erb
<tr id="dashfield"> <td><%= @user.first_name%></td> <td><%= @user.last_name %></td> <td><%= @role %></td> <td><% if @role == 'admin'%> <%= form_for @role, method: :put |f|%> <%= f.hidden_field :role, :value => 'user'%> <%= f.submit 'make user'%><%end%> <%else%> <%= form_for @role, method: :put |f| %> <%= f.hidden_field :role, :value => 'admin'%> <%= f.submit 'make admin'%> <%end%> <%end%></td> </tr>
here's controller:
class userscontroller < applicationcontroller def new @user = user.new end def index @allusers = user.all end def show @user = user.find(params[:id]) @role = @user.role end def update @user = user.find(params[:id]) if @user.update(update_user_params) redirect_to '/users' else redirect_to "/users/#{id}" end end def create @user = user.new(user_params) @user.role = 'user' if @user.save session[:user_id] = @user.id redirect_to '/hours/new' else redirect_to '/signup' end end private def user_params params.require(:user).permit(:first_name, :last_name, :email, :password) end def update_user_params params.require(:user).permit(:role) end end
is error saying cannot find databse, user? solutions problem?
your error saying:
actioncontroller::parametermissing in userscontroller#update param missing or value empty: user
because update_user_params
requires user
present in params. not present in params currently, it's throwing error.
see here know how params.require
works.
in form, can try adding this:
<%= f.hidden_field :user, { :value => @user } %>
Comments
Post a Comment