I have an admin attribute in my users model which is not getting updated, using the admin_approve action as specified, though the admin attribute of the admin is getting updated. Any suggestion or help will be appreciated.
the user controller file contains this:
def admin_approve
@users = User.paginate(page: params[:page])
end
def update_admin
@user = User.find(params[:id])
@user.update_attribute :admin, true
redirect_to (root_url)
end
the route file has this code:
get '/admin_approve', to: 'users#admin_approve'
patch '/admin_approve', to: 'users#update_admin'
the admin_approve view file:
<% @users.each do |user| %>
<%= form_for(user) do |f| %>
<%= render user %>
<%= f.label :admin, class: 'checkbox' do %>
<%= f.check_box :admin %>
Make Admin
<% end %>
<%= f.submit "Confirm", class: "btn btn-primary" %>
<% end %>
<% end %>
I have added a migration to users:
class AddAdminToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :admin, :boolean, default: false
end
end
Comments
Post a Comment