laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-20 16:37 UTC
link_to weirdness, related to namespace?
Hi,
In my app/views/admin/clieint/_searchresults.rhtml partial, I have ...
<% for user in @users %>
<tr>
<td><%=h user.ship_to_first_name %></td>
<td><%=h user.ship_to_last_name %></td>
<td><%=h user.email %></td>
<td align="center"><%= link_to ''Show'',
{:action => ''show'', :id =>
user.id} %></td>
</tr>
<% end %>
but when the link is output to the browser, it is output as "/admin/
client/2", notice that the id is there, but the action, "show" is
not. Why is link_to not outputting correctly? I''m following the
instructions from here --
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M000913.
Is it related to the "namespace" directive in my config;routes.rb
file?
Thanks, - Dave
================begin config/routes.rb file
======================ActionController::Routing::Routes.draw do |map|
map.connect '''', :controller => "register",
:action => "start"
map.resources :users
map.resources :sessions
map.signup ''/signup'', :controller =>
''users'', :action => ''new''
map.login ''/login'', :controller =>
''sessions'', :action => ''new''
map.logout ''/logout'', :controller =>
''sessions'', :action =>
''destroy''
map.change_password ''/change_password'', :controller =>
''user'', :action => ''change_password''
map.namespace :admin do |adm|
adm.resources :client, :collection => { :search
=> :get, :searchresults => :get }
end
# The priority is based upon order of creation: first created ->
highest priority.
# Sample of regular route:
# map.connect ''products/:id'', :controller =>
''catalog'', :action =>
''view''
# Keep in mind you can assign values other than :controller
and :action
# Sample of named route:
# map.purchase ''products/:id/purchase'', :controller =>
''catalog'', :action => ''purchase''
# This route can be invoked with purchase_url(:id => product.id)
# You can have the root of your site routed by hooking up ''''
# -- just remember to delete public/index.html.
# map.connect '''', :controller => "welcome"
# Allow downloading Web Service WSDL as a file with an extension
# instead of a file named ''wsdl''
map.connect '':controller/service.wsdl'', :action =>
''wsdl''
# Install the default route as the lowest priority.
map.connect '':controller/:action/:id.:format''
map.connect '':controller/:action/:id''
end
====================end config/routes.rb file
===========================
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I''d suggest removal of every route you don''t need, at least last three ones, but your problem is not there. In fact, there is no problem - link_to creates exactly what you need - GET /admin/client/2 will be routed to Admin::ClientsController#show, as you would expect. Read more on all that restful stuff. On 20 фев, 18:37, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > In my app/views/admin/clieint/_searchresults.rhtml partial, I have ... > > <% for user in @users %> > <tr> > <td><%=h user.ship_to_first_name %></td> > <td><%=h user.ship_to_last_name %></td> > <td><%=h user.email %></td> > <td align="center"><%= link_to ''Show'', {:action => ''show'', :id => > user.id} %></td> > </tr> > <% end %> > > but when the link is output to the browser, it is output as "/admin/ > client/2", notice that the id is there, but the action, "show" is > not. Why is link_to not outputting correctly? I''m following the > instructions from here --http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#.... > Is it related to the "namespace" directive in my config;routes.rb > file? > > Thanks, - Dave > > ================begin config/routes.rb file ======================> ActionController::Routing::Routes.draw do |map| > > map.connect '''', :controller => "register", :action => "start" > > map.resources :users > map.resources :sessions > map.signup ''/signup'', :controller => ''users'', :action => ''new'' > map.login ''/login'', :controller => ''sessions'', :action => ''new'' > map.logout ''/logout'', :controller => ''sessions'', :action => > ''destroy'' > map.change_password ''/change_password'', :controller => > ''user'', :action => ''change_password'' > > map.namespace :admin do |adm| > adm.resources :client, :collection => { :search > => :get, :searchresults => :get } > end > > # The priority is based upon order of creation: first created -> > highest priority. > > # Sample of regular route: > # map.connect ''products/:id'', :controller => ''catalog'', :action => > ''view'' > # Keep in mind you can assign values other than :controller > and :action > > # Sample of named route: > # map.purchase ''products/:id/purchase'', :controller => > ''catalog'', :action => ''purchase'' > # This route can be invoked with purchase_url(:id => product.id) > > # You can have the root of your site routed by hooking up '''' > # -- just remember to delete public/index.html. > # map.connect '''', :controller => "welcome" > > # Allow downloading Web Service WSDL as a file with an extension > # instead of a file named ''wsdl'' > map.connect '':controller/service.wsdl'', :action => ''wsdl'' > > # Install the default route as the lowest priority. > map.connect '':controller/:action/:id.:format'' > map.connect '':controller/:action/:id'' > end > ====================end config/routes.rb file > ===========================--~--~---------~--~----~------------~-------~--~----~You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---