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? Thanks for your help... Shagy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryan.raaum-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-11 15:54 UTC
Re: link_to in Model
On Dec 11, 9:45 am, Shagy Moe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 theModel 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> > Thanks for your help... > > Shagy > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ryan.raaum-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-11 17:52 UTC
Re: link_to in Model
Er. Quoting on my last reply had problems... The first sentence _should_ have been:>From the MVC perspective, this sort of thing does not belong in theModel as the links are part of one of many potential views of the data. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---