Hello all.  I have many questions regarding routes:
First of all, I had a route that looked like this:
map.connect ''/person/:id/
tag/:tag_id'', :controller=>:person, :action=>:tag
I was trying to link to this URL with this code:
link_to tag.name, :action=>:tag, :id=>@person.id, :tag_id=>tag.id
Instead of generating the URL I desired ( /person/1/tag/2 ), the URL
generated slipped through to my default route: /person/tag/1?tag_id=2
Question #1: Why does Rails generate the URL based on a route which is
lower in my priority list in routes.rb
When I asked this question in #rubyonrails the response I got was to
just use a named route instead.  I''m not opposed to this idea but I
would still like a real answer to Question 1.
I made a named route:
map.with_options :controller=>:person do |c|
  c.person_tag ''person/:id/tag/:tag_id'', :action=>:tag
end
This doesn''t even "compile" unless you change :person to a
string
Question #2: Why must controllers not be symbols in a named route
Linking to this named route like so: link_to tag.name,
person_tag_url(:id=>@person.id, :tag_id=>tag.id)
produces an error:
person_tag_url failed to generate from
{:controller=>"person", :action=>"tag",
:tag_id=>"13", :id=>"1"},
expected: {:controller=>"person", :action=>:tag}, diff:
{:action=>:tag, :tag_id=>"13", :id=>"1"}
For some reason it doesn''t expect my :id and :tag_id, so I''ll
try to
give it what it wants.  I change the link to:
link_to tag.name, person_tag_url()
And get this error:
person_tag_url failed to generate from
{:controller=>"person", :action=>"tag"}, expected:
{:controller=>"person", :action=>:tag}, diff: {:action=>:tag}
Looks like it wants tag to be a symbol.  Well, since I didn''t
explicitly give tag as a string, I''ll change what it expects in my
route to look like this:
map.with_options :controller=>''person'' do |c|
  c.person_tag ''person/:id/tag/:tag_id'',
:action=>''tag''
end
However, now I get the error message:
person_tag_url failed to generate from
{:controller=>"person", :action=>"tag"} - you may have
ambiguous
routes, or you may need to supply additional parameters for this
route.  content_url has the following required parameters:
["person", :id, "tag", :tag_id] - are they all satisifed?
So it looks like I''m passing the parameters it''s
"expecting" now, but
the error message I get now is that additional parameters are
required.  Supplying those parameters generates the other "failed to
generate" error described above.
Question #3: Can anybody point out what I am doing incorrectly?
Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---