Hi all,
I''m trying to code a component which is re-useable for different sites,
and
for different places within the same rails site. It''s working quite
well, but
I notice that when I use link_to (or url_for) to generate a link, it is an
''absolute'' link, rather than being relative to where the
component is being
displayed.
For example;
Say my application has pages for different people. The page for user
''craig''
is at the url:
hostname/people/show/craig/
On that page, I wish to put my component, which is a discussion thread
(basically, a list of comments). The show action for my people controller
loads the component, using the action ''index''. The index
action of the
component loads the view index.rhtml. Within that, I display the headings of
all the comments, with a link to their ''show'' action to see
more detail.
<%= link_to(''Read More'', {:action => "show",
:id => 1) %>
Currently, this takes my application to the URL:
hostname/people/show/1
The controller is "people", only because I didn''t specify one
explicitly, so
it used the controller in the current route (the people one, not the
component one). If I specify the controller as the component, I get:
hostname/comments/show/1
This isn''t right either.
What I want, is the URL:
hostname/people/show/craig/comments/show/1
Obviously I can create this string myself, but I think that this is the way
that link_to should always work for components. Components don''t know
in what
context they are being used, and they shouldn''t need to know. They
should be
able to link to other pages which are part of the component, without changing
the page that loaded the component.
What do other people think about this? Am I the only person attempting to
write third party components? :)
regards,
Craig
--
Craig Ambrose
Web Elements
http://www.portallus.com/people/craigambrose/