Restrict Access to Create Action to Particular User Model?

39 views
Skip to first unread message

David Williams

unread,
Jan 8, 2015, 3:02:47 PM1/8/15
to rubyonra...@googlegroups.com
I have two user models one for businesses and one for buyers. How would
I be able to restrict the create method only for businesses and allow
the show actions only for buyers?

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Jan 8, 2015, 4:08:59 PM1/8/15
to rubyonra...@googlegroups.com
On 8 January 2015 at 20:01, David Williams <li...@ruby-forum.com> wrote:
> I have two user models one for businesses and one for buyers. How would
> I be able to restrict the create method only for businesses and allow
> the show actions only for buyers?

Have a look at the cancan gem for handling roles.

Colin

David Williams

unread,
Jan 8, 2015, 4:19:29 PM1/8/15
to rubyonra...@googlegroups.com
Colin Law wrote in post #1166335:
Alright, I will check it out. thank you.

Vivek Sampara

unread,
Jan 9, 2015, 1:43:38 AM1/9/15
to rubyonra...@googlegroups.com
David, 

Have a look at pundit gem as well. I'd recommend that for simplicity. 

Vivek

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e5b57351ddd56699cdf725caf6708d79%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Jason Fleetwood-Boldt

unread,
Jan 9, 2015, 9:53:02 AM1/9/15
to rubyonra...@googlegroups.com

On that note, I think cancan is cancancan now?

(https://github.com/ryanb/cancan vs https://github.com/CanCanCommunity/cancancan)

Does anyone know what happened there? I think Ryan Bates took a break or something?
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtLMJ-AMAfaMefRM7LngwkSbcm2hHs7B153KaQkS5cYhw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

----

Jason Fleetwood-Boldt
te...@datatravels.com
http://www.jasonfleetwoodboldt.com/writing

All material © Jason Fleetwood-Boldt 2014. Public conversations may be turned into blog posts (original poster information will be made anonymous). Email ja...@datatravels.com with questions/concerns about this.

David Williams

unread,
Jan 9, 2015, 3:50:05 PM1/9/15
to rubyonra...@googlegroups.com
Jason Fb wrote in post #1166396:
> On that note, I think cancan is cancancan now?
>
> (https://github.com/ryanb/cancan vs
> https://github.com/CanCanCommunity/cancancan)
>
> Does anyone know what happened there? I think Ryan Bates took a break or
> something?
>
> Jason Fleetwood-Boldt
> te...@datatravels.com
> http://www.jasonfleetwoodboldt.com/writing
>
> All material © Jason Fleetwood-Boldt 2014. Public conversations may be
> turned into blog posts (original poster information will be made
> anonymous). Email ja...@datatravels.com with questions/concerns about
> this.

I installed the original cancan. Which is working, but I have the
slightest clue to what's going on with cancancan.

j...@room118solutions.com

unread,
Jan 12, 2015, 12:48:25 PM1/12/15
to rubyonra...@googlegroups.com
+1 for Pundit.  I prefer it over CanCan these days, especially for your use-case.

Jim

David Williams

unread,
Jan 12, 2015, 4:28:56 PM1/12/15
to rubyonra...@googlegroups.com
unknown wrote in post #1166545:
> +1 for Pundit. I prefer it over CanCan these days, especially for your
> use-case.
>
> Jim

Alright, I'll uninstall CanCan for Pundit. Thanks.

Colin Law

unread,
Jan 12, 2015, 4:33:12 PM1/12/15
to rubyonra...@googlegroups.com
On 12 January 2015 at 21:28, David Williams <li...@ruby-forum.com> wrote:
> unknown wrote in post #1166545:
>> +1 for Pundit. I prefer it over CanCan these days, especially for your
>> use-case.
>>
>> Jim
>
> Alright, I'll uninstall CanCan for Pundit. Thanks.

Try them both and then use the one that most suits your needs. Anyway
you do not need to uninstall cancan, just remove if from Gemfile and
insert pundit instead (plus making any changes to the code of course).

Colin

David Williams

unread,
Jan 12, 2015, 4:42:10 PM1/12/15
to rubyonra...@googlegroups.com
Colin Law wrote in post #1166563:
Sounds cool. Thank you.
Reply all
Reply to author
Forward
0 new messages