Only showing models in Nav bar for Admin users (administrate)
Hi
I'm on a pretty steep learning curve here. I thought I was pretty good at Rails until using this template! I'm determined to not let it beat me!
When adding a new dashboard using administrate it seems to place a link into _left_nav.html.erb. It seems that this is displayed for all users regardless of admin (or not). Logged in (or not). How do I stop this from happening (or only show for admin users?).
It seems odd that "standard" users can access and create models in the database.
I've tried to follow the docs for administrate, but they don't appear that helpful to me
Thanks
I'm on a pretty steep learning curve here. I thought I was pretty good at Rails until using this template! I'm determined to not let it beat me!
When adding a new dashboard using administrate it seems to place a link into _left_nav.html.erb. It seems that this is displayed for all users regardless of admin (or not). Logged in (or not). How do I stop this from happening (or only show for admin users?).
It seems odd that "standard" users can access and create models in the database.
I've tried to follow the docs for administrate, but they don't appear that helpful to me
Thanks
As far as I know, the link is placed in the left nav bar under the assumption that the models you're creating are resources that your users will be creating, reading, editing and destroying during their use of the app.
Standard users can't create models in the database but they can CRUD records for those models.
The admin access for those models is in the right dropdown nav bar section that is only visible to admin users.
Standard users can't create models in the database but they can CRUD records for those models.
The admin access for those models is in the right dropdown nav bar section that is only visible to admin users.
In the end I think it made more sense to do the following in _navbar.html.erb as I like the idea of me having access to the models, but not the users:
<div class="text-sm lg:flex-grow"> <%- if user_signed_in? && current_user.admin? %> <%= render "shared/left_nav" %> <%- end %> </div>
Thanks
Here’s an example of what I’m talking about: my latest app allows users to sign up for an account and create videos. In this case it makes sense for my Videos resource to be visible to the user. They will create, view (read), update and destroy videos in their account.
However I also have an Encodes model that keeps track of the details about the creation of the video - how long it took to process, the video duration, file size, etc. This resource will not be visible to the user since it’s all on the backend.
The confusion likely arises because Jumpstart puts links for all models you create in the left nav. It doesn’t know whether the resource you added is user-facing or not. It’s just put there as a convenience for the developer. You must decide which resources to expose to the user within the app.
On a side note - all the models you create are available to admins (probably just you) in the right-hand dropdown nav. There’s no need to ya do them at all in the left nav.
On another side note - I’d use the following as a conditional to show/hide depending on admin:
current_user && current_user.admin?
I feel like it reads easier, showing that you’re progressively checking the current user. Your way could read as checking two separate, unrelated things.
Notifications
You’re not receiving notifications from this thread.