I am using devise for authentication on a client app. After extensive reading of the wiki, I managed to configure my app to suit my needs properly. However I have a CSS loading problem.
I chose the option of allowing an admin approve an account over :confirmable
as I am not familiar with combining both :confirmable
and approving the account.
I followed the instructions in "How To: Require admin to activate account before sign_in" to do just that and "How to do browser-based new user approval by Admin in Rails 3.2 using Devise" to help with configuring my routes.rb
file when updating the attribute.
The issue now is, when I click the link to update the attribute, it does so flawlessly but the path for finding CSS after redirecting back changes.
To clarify what I mean, let's say my CSS file is in public/user/mycss.css
, when I sign in with devise, it loads properly but upon clicking the link_to
tag it updates the record, but looks for mycss.css
via users/:id/approve/mycss.css
which doesn't exist with reference to the second link.
I have an admin model that allows the client to create posts for a blog. The authentication system works flawlessly. The devise wiki link in the first link suggested that I list all the users and create a method that is simple and efficient to update the approved attribute. In my controller I have this code:
def approve_admin
admin = Admin.find(params[:id])
unless admin.approved?
admin.update_attribute :approved, true
if admin.save
flash[:notice] = "#{admin.first_name} approved"
else
flash[:alert] = "#{admin.first_name} approval failure"
end
end
redirect_to :back
end
In my view I use a link_to
tag that updates the attribute using the above method:
<% if !(admin.approved?) %>
<p class="hvr-shutter-out-horizontal hvr-grow-shadow"><%= link_to "Approve", approve_admin_path(admin.id) %></p>
<% end %>
In my routes file I have this:
get 'admin/:id/approve', to: 'posts#approve_admin', as: 'approve_admin'
This works perfectly but then the CSS and JavaScript files do not load. I inspected the browser for errors and this was the output:
http://localhost:3000/admin/3/js/modernizr.custom.js
for example, instead of loading the files from
http://localhost:3000/admin/js/modernizr.custom.js
Why is it looking for the CSS file via that path?