Hi all,
I am wondering how I can simplify my life with link_to. I've got a lot of pages with some of the same links and the views are getting messy. What I'd like to do is create something like this for the Model.
def more_info_link link = link_to "More Info", { :action => "model_details", :id => self.id} end
def reviews_link link = link_to "Reviews", { :action => "model_reviews", :id => self.id} end
and then, in the view, I could just do something like this:
<%= Model.more_info_link -%> <%= Model.reviews_link -%>
So, when I try this, I get a "undefined method `link_to' for #<Model" error.
I've successfully put this in the controller helper, passing the Model id as an arguement, but I don't like that solution... Should I create a new class extending UrlHelper? What is the best way to implement something like this?
From the MVC perspective, this sort of thing does not belong in the
Model as the links are part of one of many potential views of the data.
I'd say that the helper method you've tried (but don't like) is probably the best solution.
-r