Namespaces, dynamic links and routing

Hello all!

I am new to all of this and I am trying to accomplish a couple things, I am hoping that someone will be able to assist me…

First -

I am trying to set up a namespace within a dynamic link. I have created an admin namespace and I need to following link to go to ../admin/people/xxx

<div class="inner">
  <p><%= link_to(person) do %>
      <strong><%= person.fname %> <%= person.lname %></strong>
  <% end %></p>
  <p><%= person.title %></p>
  <p><%= person.position.capitalize %></p>
</div>

Secondly, the current route resolves to address.com/people/{:id} and I would like to it resolve to address.com/{:user_name} and I am not sure how to get this to work. I have tried a few different options but I am not quite sure what I am doing here.

resources :people, only: [:index, :show] do
    resources :pubs, except: [:create, :new, :edit, :destroy]
end

I have attempted to add —> get 'people/:id/user_name' => 'people#user_name', as: :user_name
but this has not worked.

Thanks for any help!

Jason

Hi Jason,

I assume you're talking about Ruby on Rails. Please correct me if I'm wrong.

1. There are a couple of ways of generating links but I think the clearest
is using a URL helper. You can see all the helpers corresponding to
routes.rb by invoking `rake routes`. The first column is the helper's
prefix. For example, if it reads `users` then the corresponding helpers
`users_url` (full URL, including schema, host and port) and `users_path`
(only the path component).

2. If I understand your intent correctly then you want to do: get
":user_name", to: "people#show". For example /greg will be routed to
PeopleController#show action and params[:user_name] will be set to "greg".

Hope that helps.
Greg Navis

···

On Wed, Nov 4, 2015 at 6:28 PM, Jason Orman <orman@neuro.fsu.edu> wrote:

Hello all!

I am new to all of this and I am trying to accomplish a couple things, I
am hoping that someone will be able to assist me…

First -

I am trying to set up a namespace within a dynamic link. I have created an
admin namespace and I need to following link to go to ../admin/people/xxx

<div class="inner">
        <p><%= link_to(person) do %>
                <strong><%= person.fname %> <%= person.lname %></strong>
        <% end %></p>
        <p><%= person.title %></p>
        <p><%= person.position.capitalize %></p>
</div>

Secondly, the current route resolves to address.com/people/{:id} and I
would like to it resolve to address.com/{:user_name} and I am not sure
how to get this to work. I have tried a few different options but I am not
quite sure what I am doing here.

resources :people, only: [:index, :show] do
    resources :pubs, except: [:create, :new, :edit, :destroy]
end

I have attempted to add —> get 'people/:id/user_name' =>
'people#user_name', as: :user_name
but this has not worked.

Thanks for any help!

Jason

Also, if that is the case, other forums (Rails specific ones) might be able
to provide better support.

Cheers

robert

···

On Wed, Nov 4, 2015 at 8:34 PM, Greg Navis <contact@gregnavis.com> wrote:

I assume you're talking about Ruby on Rails. Please correct me if I'm
wrong.

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can -
without end}
http://blog.rubybestpractices.com/