Re: [Rails] Re: Proper Coding Question

2018-10-05 Thread Walter Lee Davis
> On Oct 5, 2018, at 4:17 AM, Rob Jonson wrote: > > again - taste and preference here. > > my issue with `policy_scope(User)` in the view isn't that it is complex > code, clearly it isn't. > > it's more that I don't want my view to know or care about authorisation. > > I think when

[Rails] Re: Proper Coding Question

2018-10-05 Thread Rob Jonson
again - taste and preference here. my issue with `policy_scope(User)` in the view isn't that it is complex code, clearly it isn't. it's more that I don't want my view to know or care about authorisation. I think when you're talking about a select 'policy_scope(User).collect', you're asking

[Rails] Re: Proper Coding Question

2018-10-04 Thread Eric Anderson
I agree with Rob that it is in the realm of taste and preference. I wouldn't have something like this in my view: users = User.where(active: true).join(:transactions).merge(Transaction.where('total > 1000')) form.collection_select users, :id, :name This would be putting model level

[Rails] Re: Proper Coding Question

2018-10-04 Thread John Sanderbeck
Ok, that makes sense... Everything is working fine the way it is coded but I am fairly new to RoR and want to learn proper practices. One of the things I do with pundit is to filter the data by a particular School District, so in the "scope" of Pundit I look to see what role the user has and

[Rails] Re: Proper Coding Question

2018-10-04 Thread Rob Jonson
Hi John, firstly - I don't know pundit, so this is only general advice. secondly - we're definitely in the realm of taste and preference here rather than 'ok' and 'not ok' having said that, my two pence: the rails style guide says 'Never call the model layer directly from a view'

[Rails] Re: Proper Coding Question

2018-10-03 Thread John Sanderbeck
Excellent... So it's OK to call policy_scope(User) from a view? That's what I was confused by... On Wednesday, October 3, 2018 at 12:44:52 PM UTC-4, Eric Anderson wrote: > > There is an `collection_select` form builder that will do the `collect` > for you. So: > > <%= f.collection_select

[Rails] Re: Proper Coding Question

2018-10-03 Thread Eric Anderson
There is an `collection_select` form builder that will do the `collect` for you. So: <%= f.collection_select :user, policy_scope(User), :id, :name %> If you are not using a form builder then `options_from_collection_for_select` is useful for the same purpose. If those helpers cannot be