# Admin link in application helper

**URL:** <https://www.ruby-forum.com/t/admin-link-in-application-helper/170890>\
**Category:** Rails\
**Created:** [June 24, 2009, 1:37am UTC](https://www.ruby-forum.com/t/admin-link-in-application-helper/170890 "2009-06-24T01:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [June 24, 2009, 1:37am UTC](https://www.ruby-forum.com/t/admin-link-in-application-helper/170890/1 "2009-06-24T01:37:25Z")

</div>

hello,

Im trying to create a helper method for my admin links. in quite a few  
views i have the code

\<% if current\_user %\>  
\<%= link\_to “Edit”, edit\_model\_path(model) %\>  
\<%= link\_to “New”, new\_model\_path %\>  
\<%= link\_to “Delete”, model, :confirm =\> “Your a Noob”, :method  
=\> :delete %\>  
\<% end %\>

that only display these when logged in.

I would like to do something like this in their place

\<%= admin\_links(model) %\>  
and pass the current item into the application helper method

def admin\_links(m)  
if current\_user  
a = “#{link\_to “edit” edit\_m\_path(m)}”  
a \<\< “#{link\_to “new” new\_m\_path}”  
a \<\< “#{link\_to “Delete”, m, :confirm =\> “Your a Noob”, :method  
=\> :delete}”  
end  
end

Or something of the like. Im not as skilled in the way of helpers but  
would like to be.

any help would be great.

Thanks in advance

Bob

---

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [June 26, 2009, 7:53am UTC](https://www.ruby-forum.com/t/admin-link-in-application-helper/170890/2 "2009-06-26T07:53:09Z")

</div>

Here is how I have done it.

In routes:

map.namespace(:admin) do |admin|  
admin.resources :users, :member=\>{:edit\_password=\>:get,  
:update\_password=\>:post }  
admin.resources :suppliers  
admin.resources :categories  
end

Now just use admin in the path methods  
eg.  
= link\_to ‘Edit’, edit\_admin\_user\_path(@user)  
= link\_to ‘Password’, edit\_password\_admin\_user\_path(@user)  
= link\_to ‘Back’, admin\_users\_path

In the form:  
form\_for [:admin,@user] do |f|

But have a look at the routing section on the railsguides site. There  
are quite a few options for setting up routes and I still have to play  
with some of them myself.

I am actually planning to eliminate the need for admin in my path  
methods by using :name\_prefix=\>nil in the route. I think I did this  
somewhere once when I needed to move a resource into the admin  
namespace. It simplifies the process since the paths don’t need to be  
edited. But then admin wont appear or be required in the url.

Tonypm
