I have a model I extended w/STI to allow me to write little widgets or
modules for my web-app … that part’s working well. However, I’m
to the point where, depending on the model’s type/class I would like to
render a partial so that each type has it’s own look/feel/content.
Has anyone tried this sort of thing before? I’m trying to do a simple
link_to for a nested resource (which works fine within the context of a
straight view, but I get this when calling the partial from my model(s)
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.url_for
work. As mentioned in the comments to that blog post
Hi Joel. I’m not quite sure why you want to render partials or
templates from within your model(s). I’m sure you have some good
reasons, but sometimes there’re ways of accomplishing what you want
without violating the “rules” of the MVC design pattern.
Would you mind explaining in more detail why your model(s) need to
render partials and/or templates?
Second - the reason why I’m trying to do this is to allow whatever type
widget model I’m creating to render its own particular partial, in the
context of the “area” a user will place it - header, footer, sidebar,
I thought that calling a helper to weed out the objects for a particular
“area” and then letting the model call its partial on its own, would be
easier way to do it, despite the normal MVC rules. I know it’s against
rules - so I’m wondering if there’s an easier way?
Weeks later I finally got around to figuring out how to best tackle this
your suggestion was right on the money. I didn’t want to let this lie
without mentioning that the best bet started with that nugget from the
pastie link. Thanks Nick
Weeks later I finally got around to figuring out how to best tackle
this and your suggestion was right on the money. I didn’t want to
let this lie without mentioning that the best bet started with that
nugget from the pastie link. Thanks Nick
I’m glad to hear it helped! Good luck, mate.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.