Hi Ahmy,

I think this is going to be a bad idea.  What I'm guessing your trying
to do is override to_s so you can do something like...

<ol>
<%= news_entry.news_tags %>
</ol>

And in that to_s you'd wrap the individual news_tag objects with some
<li> HTML and such.  If you really want to do this, you'd need to
monkey-patch the Array class since news_entry.news_tags is an Array.

It would be much better to write a helper so your view code is like...

<%= tag_list(news_entry.news_tags) %>

Then in your news_entry_helper.rb something like this...

def tag_list(tags)
  output = "<ol>"
  tags.each{|t| output << "<li>#{t}</li>"}
  output << "</ol>"
end

Cool?

- Jeff

---
Jeff Casimir
Jumpstart Lab by Casimir Creative, LLC
http://jumpstartlab.com
@jumpstartlab on twitter
Rails Jumpstart - Aug 15&16 - Beginning Web Application Development
JavaScript Jumpstart - Sep 12 - Intermediate Javascript Programming & UI
Robotics Jumpstart - Sep 13 - Intro to Robotics with Lego Mindstorms NXT



On Fri, Aug 14, 2009 at 1:18 PM, Ahmy Yulrizka<yulri...@gmail.com> wrote:
> Hi, im trying to modify an extension
> basically .. i have this model
>
> class NewsEntry < ActiveRecord::Base
>  has_and_belongs_to_many :news_tags , :join_table => 'news_entries_news_tags'
> end
>
> so an instance of NewsEntry let say news_entry.
> news_entry will have the method news_entry.news_tags
>
> i want to override the news_entry.news_tags.to_s method.
> how can i do that ?
>
> thanks before
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
>
_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to