# Restful urls and has\_permission?

**URL:** <https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346>\
**Category:** Rails\
**Created:** [June 8, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346 "2007-06-08T20:27:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 8, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/1 "2007-06-08T20:27:59Z")

</div>

hey all,

I’m using simple\_access\_control this way:

\<%= link\_to ‘list’, :controller=\>‘profiles’,:action=\>‘list’ if  
has\_permission?(‘admin’)%\>

and now that I’m using restful path it doesn’t seem to work anymore:

\<%= link\_to ‘list’, list\_profiles\_path if has\_permission?(‘admin’)%\>

anyone had the same problem and found a workaround?

thanx in advance

Pat

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 8, 2007, 11:37pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/2 "2007-06-08T23:37:27Z")

</div>

On 6/8/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= link\_to ‘list’, list\_profiles\_path if has\_permission?(‘admin’)%\>
> 
> anyone had the same problem and found a workaround?

You didn’t give an error message, so there’s no way to tell, but I’d  
guess that your given route doesn’t exist. Read the docs for an  
overview of the routes that map.resources creates:  
[http://rails.rubyonrails.org/classes/ActionController/Resources.html](http://rails.rubyonrails.org/classes/ActionController/Resources.html)

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 5:01am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/3 "2007-06-09T05:01:01Z")

</div>

On 6/8/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I do have this in my route:  
> map.resources :shootings, :collection =\>{:list =\> :get, :search =\> :get}

I meant:  
map.resources :profiles, :collection =\>{:list =\> :get, :search =\>  
:get}

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 6:10am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/4 "2007-06-09T06:10:05Z")

</div>

Patrick,

it’s definitely helpful to see the map.resources call you’re making  
(and I assume that’s literally what you’ve right? As in, you’re not  
failing to tell us that it’s a nested resource or something?).

Even so, this isn’t enough information to go on. You need to supply  
details of any error messages and any other clues about what happens  
when list\_profiles\_path() executes.

“doesn’t work any more” is too vague I’m afraid.

Regards,  
Trevor

On 6/8/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 6/8/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I do have this in my route:  
> > map.resources :shootings, :collection =\>{:list =\> :get, :search =\> :get}
> 
> I meant:  
> map.resources :profiles, :collection =\>{:list =\> :get, :search =\> :get}
> 
> >

## –

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 5:00am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/5 "2007-06-09T05:00:01Z")

</div>

On 6/8/07, Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You didn’t give an error message, so there’s no way to tell, but I’d  
> guess that your given route doesn’t exist. Read the docs for an  
> overview of the routes that map.resources creates:  
> [http://rails.rubyonrails.org/classes/ActionController/Resources.html](http://rails.rubyonrails.org/classes/ActionController/Resources.html)

I do have this in my route:  
map.resources :shootings, :collection =\>{:list =\> :get, :search =\>  
:get}

should I add something? I don’t have any error from the log.

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 7:07am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/6 "2007-06-09T07:07:09Z")

</div>

There isn’t any error message, it’s just that when I use:

\<%= link\_to ‘list’, :controller=\>‘profiles’,:action=\>‘list’ if  
has\_permission?(‘admin’)%\>

the link is not display if the current\_user is not part of the admin  
role. But when I use:

\<%= link\_to ‘list’, list\_profiles\_path if has\_permission?(‘admin’)%\>

the link is displayed whether the current\_user is part or not of the  
admin role. I couldn’t spot any error message 😕

> failing to tell us that it’s a nested resource or something?).  
> No it’s not a nested resource.

thanx in advance

Pat

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/7 "2007-06-09T17:07:14Z")

</div>

On 6/9/07, Trevor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Okay, this does seem odd.
> 
> If you try:
> 
> \<%= link\_to ‘list’, list\_profiles\_path if false %\>
> 
> and the link does _not_ get displayed then your assumptions about  
> has\_permission?(:admin) are wrong because clearly it’s returning true  
> when you don’t expect.

The link doesn’t get display if I put “false”.

> however, if it _does_ display the link then you seem to have some  
> strange parsing problem (that doesn’t make sense to me). Try changing  
> it to this:
> 
> \<%= link\_to(‘list’, list\_profiles\_path) if has\_permission?(:admin) %\>

doesn’t solve the problem 😕  
maybe it’s because the plugin I’m using is kind of old (08/2006) and  
can’t parse restful path?  
([http://mabs29.googlecode.com/svn/trunk/plugins/simple\_access\_control](http://mabs29.googlecode.com/svn/trunk/plugins/simple_access_control))

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/8 "2007-06-09T17:49:19Z")

</div>

> > \<%= link\_to(‘list’, list\_profiles\_path) if has\_permission?(:admin) %\>
> 
> doesn’t solve the problem 😕  
> maybe it’s because the plugin I’m using is kind of old (08/2006) and  
> can’t parse restful path?  
> ([http://mabs29.googlecode.com/svn/trunk/plugins/simple\_access\_control](http://mabs29.googlecode.com/svn/trunk/plugins/simple_access_control))

It’s an if loop, you need to verify that has\_permission? is working.  
Trevor’s “if false” trick proved that the syntax and the link are  
correct.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 7:27am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/9 "2007-06-09T07:27:10Z")

</div>

Okay, this does seem odd.

If you try:

\<%= link\_to ‘list’, list\_profiles\_path if false %\>

and the link does _not_ get displayed then your assumptions about  
has\_permission?(:admin) are wrong because clearly it’s returning true  
when you don’t expect.

however, if it _does_ display the link then you seem to have some  
strange parsing problem (that doesn’t make sense to me). Try changing  
it to this:

\<%= link\_to(‘list’, list\_profiles\_path) if has\_permission?(:admin) %\>

HTH,  
Trevor

On 6/8/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> >

## –

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/10 "2007-06-09T22:13:48Z")

</div>

As we come to the point where it is determined that has\_permission? is  
not behaving as expected.  
The most reasonable thing you can do is to do a little debugging to  
determine what’s happening.

I do not use simple\_access\_control, but if you find the cause for this  
behavior and way to fix it the community will appreciate your effort.

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/11 "2007-06-09T18:09:20Z")

</div>

On 6/9/07, Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s an if loop, you need to verify that has\_permission? is working.  
> Trevor’s “if false” trick proved that the syntax and the link are  
> correct.

Well, it looks like has\_permission? is not working with restful path,  
this is why I asked in my initial post if any of you using the  
simple\_access\_control plugin had the same problem with  
has\_permission? and restful path, sorry if I didn’t make it very  
clear. If you’re not using simple\_access\_control then I guess you  
can’t help me on that issue (unless you install it and test it for me  
:).

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 9, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/12 "2007-06-09T22:16:49Z")

</div>

Today I find the [http://unroller.rubyforge.org/](http://unroller.rubyforge.org/) - Ruby Unroller is a  
tool for generating human-readable “execution traces”. While it is  
enabled, it will watch every Ruby statement and method call that gets  
executed and will display the source code on your screen in real-time  
as it is being executed.

Perhaps you will get a better view on what is going on in your app.

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 10, 2007, 12:44am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/13 "2007-06-10T00:44:02Z")

</div>

On 6/9/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Actually that’s the first thing I did before posting to the list but  
> the code was a little scriptic

I meant cryptic of course 🙂

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 10, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/14 "2007-06-10T21:32:02Z")

</div>

The SimpleAccessControl code snippet shows that it depend on  
user.roles data.  
I spouses that you do the installation procedure described in Readme  
file.  
But in any case check the data in database and check the  
SimpleAccessControl:: AccessControlHandler#check method 🙂

# The heart of the system, all credit to Ezra for the original

algorithm

# Defaults to false if there is no user or that user does not have a

roles association

# Defaults to true if the role is blank

```
def check(role, user)
  return(false) if user.blank? || !user.respond_to?(:roles)
  return(true) if role.blank?
  user.roles.map{ |r| r.title.downcase }.include? role.downcase
end

```

On Jun 10, 12:42 am, “Patrick A.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 6/9/07, Patrick A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Actually that’s the first thing I did before posting to the list but  
> > the code was a little scriptic
> 
> I  
> meant cryptic of course 🙂

---

<div class="post-metadata">

**Author:** ![patcito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/50afbb/32.png) [@patcito](https://www.ruby-forum.com/u/patcito)\
**Post date:** [June 10, 2007, 12:43am UTC](https://www.ruby-forum.com/t/restful-urls-and-has-permission/106346/15 "2007-06-10T00:43:02Z")

</div>

On 6/9/07, dima [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> As we come to the point where it is determined that has\_permission? is  
> not behaving as expected.  
> The most reasonable thing you can do is to do a little debugging to  
> determine what’s happening.

Actually that’s the first thing I did before posting to the list but  
the code was a little scriptic for a noob like me so I asked to the  
list :-). I’m gonna give it another try though.
