We've moved discussions to Discord

Only showing models in Nav bar for Admin users (administrate)

Darren Smyth
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
you can just delete the link in _left_nav.html.erb.
or do this 
<%= link_to 'foo', foo_path if user.admin? %>
Dan Weaver
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.
Darren Smyth
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  LarryTu and  Dan Weaver for your help.

Dan Weaver : I wonder if allowing users to CRUD resources is a good idea? I am updating the website I already have (http://www.maffsguru.com) to allow for card payments, admin interface, API etc. The idea that users could add their own videos or change the details for anything in the many models I need to run the site would somewhat worry me :( Or have I got the target audience for jumpstartpro wrong? I was hoping to adapt it to allow me to write a "standard" site but with a lot more of the functionality which I couldn't implement myself without giving the users too much visibility of the backend.
Dan Weaver
Darren Smyth I think we’re talking at cross purposes here. Likely I didn’t explain myself well enough.

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. 
Justin Zimmerman
In the documentation there is a video or screencast for a content business "like netflix". That will show you how to make it so only admins can CRUD and users can only view/show
Notifications
You’re not receiving notifications from this thread.