Ruby on Rails Thursday, June 30, 2011

Hi all. I'm having some trouble with nested routes and duplicate
namespaces.
I have an Article and Advert model, both with an associated
Publication model:


class Article
has_one :publication
end

class Article::Publication
belongs_to :article
end

class Advert
has_one :publication
end

class Advert::Publication
belongs_to :advert
end


Each Publication model is different enough that it makes no sense to
have just one Publication model with STI or polymorphism. Also,
there are numerous other models such as Cancellation, Payment etc that
are namespaced for the same reason.

here's the routes I have for the above resources:

resources :articles do
resource :publication, :module => :article
end

resource :adverts do
resource :publication, :module => :article
end


this gives me article_publication_path and advert_publication_path
which are fine. The problem occurs with polymorhic_url (used by
form_for). Given [@article, @publication], it will try to generate
article_article_publication_url which of course hasn't been defined.
I've tried several of the options in the rails routing guide to no
avail so for now, I'm manually specifying the path in form_for

has anyone come across something similar or do you know of a potential
solution?

thanks, Ev

--
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@googlegroups.com.
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.

No comments:

Post a Comment