Hi Folks, Good evening, I used the code which i print below, Yes i got the result , but i need the result like this "TruncateHtml is jus....(continued)" some_html = ''<ul><li><a href="http://whatever">TruncateHtml is just like the vanilla truncate rails helper , TruncateHtml is just like the vanilla truncate rails helper</a></li></ul>'' truncate_html(some_html, :length => 15, :omission => ''...(continued)'') => <ul><li><a href="http://whatever">This...(continued)</a></li></ul> please advice. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ZMCPdfHXP6sJ. For more options, visit https://groups.google.com/groups/opt_out.
Hi dude, I think you did wrong by truncating then html. Besides, when you use '':omission'' option, the computed length take in consideration the length of ''...(continued)''. The best way to do this would be to create a helper method like truncate_text truncate_text(text, length, end_text) end_text ||= '''' # end_text as an optional parameter new_text = truncate(text, :length => length) new_text = new_text + end_text new_textend And then use it in you r html like this: some_text = "TruncateHtml is just like the vanilla truncate rails helper , TruncateHtml is just like the vanilla truncate rails helper" <ul><li><a href=''#''><%= truncate_text(some_text, 15, (continued)) %></a></li></ul> Good luck Lionel 2013/2/5 Maddy <ashokkumar-tks5Z7IV8F8RmelmmXo44Q@public.gmane.org> Hi Folks,> > Good evening, > > I used the code which i print below, > > Yes i got the result , but i need the result like this "TruncateHtml is jus....(continued)" > > some_html = ''<ul><li><a href="http://whatever">TruncateHtml is just like the vanilla truncate rails helper , TruncateHtml is just like the vanilla truncate rails helper</a></li></ul>'' > > truncate_html(some_html, :length => 15, :omission => ''...(continued)'') > => <ul><li><a href="http://whatever">This...(continued)</a></li></ul> > > please advice. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/ZMCPdfHXP6sJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- *lionel Bastian LONKAP TSAMBA* Étudiant 5e année Génie Informatique et Statistiques à Polytech-lille Site: http://first-developer.fr Email: lionel.firstdeveloper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Tel: +336 12 48 03 01 -- *lionel Bastian LONKAP TSAMBA* Fifth year student in Software Engineering and Statistics at the Lille University Graduate School of Engineers (Polytech-Lille) Site: http://first-developer.fr Email: lionel.firstdeveloper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Phone: +336 12 48 03 01 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Hi dude, Good Day, My some_text content like this = "<p>TruncateHtml is just like the <strong>vanilla truncate <strong>rails helper , TruncateHtml is just like the vanilla truncate rails helper<p>" As you said i pasted helper code in my pp_helper.rd and in my view, app_helper.rb def truncate_text(text, length, end_text) end_text ||= '''' # end_text as an optional parameter new_text = truncate(text, :length => length) new_text new_text + end_text new_text end my_view - some_text = raw a.content = truncate_text(some_text, 15) I got an error wrong number of arguments (2 for 3) Extracted source (around line *#147*): 144: = raw a.name 145: .ra 146: - some_text = a.content 147: = truncate_text(some_text, 15) 148: .con12 149: = "read more.." 150: .alert_msg Please advice. On Tue, Feb 5, 2013 at 5:48 PM, lionel Lioninho < lionel.firstdeveloper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi dude, > > I think you did wrong by truncating then html. Besides, when you use > '':omission'' option, the computed length take in consideration the length of > ''...(continued)''. The best way to do this would be to create a helper > method like truncate_text > > truncate_text(text, length, end_text) > end_text ||= '''' # end_text as an optional parameter > new_text = truncate(text, :length => length) > new_text = new_text + end_text > new_textend > > And then use it in you r html like this: > > some_text = "TruncateHtml is just like the vanilla truncate rails helper , TruncateHtml is just like the vanilla truncate rails helper" > > <ul><li><a href=''#''><%= truncate_text(some_text, 15, (continued)) %></a></li></ul> > > > Good luck > > > Lionel > > > 2013/2/5 Maddy <ashokkumar-tks5Z7IV8F8RmelmmXo44Q@public.gmane.org> > > Hi Folks, >> >> Good evening, >> >> I used the code which i print below, >> >> Yes i got the result , but i need the result like this "TruncateHtml is jus....(continued)" >> >> >> >> some_html = ''<ul><li><a href="http://whatever">TruncateHtml is just like the vanilla truncate rails helper , TruncateHtml is just like the vanilla truncate rails helper</a></li></ul>'' >> >> truncate_html(some_html, :length => 15, :omission => ''...(continued)'') >> => <ul><li><a href="http://whatever">This...(continued)</a></li></ul> >> >> please advice. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/ZMCPdfHXP6sJ. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > -- > > *lionel Bastian LONKAP TSAMBA* > Étudiant 5e année Génie Informatique et Statistiques à Polytech-lille > > Site: http://first-developer.fr > > Email: lionel.firstdeveloper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > Tel: +336 12 48 03 01 > > -- > > *lionel Bastian LONKAP TSAMBA* > > Fifth year student in Software Engineering and Statistics > > at the Lille University Graduate School of Engineers (Polytech-Lille) > > Site: http://first-developer.fr > > Email: lionel.firstdeveloper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > Phone: +336 12 48 03 01 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- *"Attitude is a little thing that makes a big difference"* Thanks & Regards *Ashokkumar.Y* *ROR-Developer **email : ashokkumar-tks5Z7IV8F8RmelmmXo44Q@public.gmane.org* *Shriramits* * * -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 6 February 2013 04:22, Ashokkumar Yuvarajan <ashokkumar-tks5Z7IV8F8RmelmmXo44Q@public.gmane.org> wrote:> > Hi dude, > > Good Day, > > My some_text content like this = "<p>TruncateHtml is just like the <strong>vanilla truncate <strong>rails helper , TruncateHtml is just like the vanilla truncate rails helper<p>" > > As you said i pasted helper code in my pp_helper.rd and in my view, > > app_helper.rb > def > truncate_text(text, length, end_text)How many arguments has this method got?> > end_text ||= '''' # end_text as an optional parameter new_text = truncate(text, :length => length) new_text = new_text + end_text new_text end > > my_view > - some_text = raw a.content > = truncate_text(some_text, 15)How many arguments are you passing?> > I got an error > > wrong number of arguments (2 for 3)I wonder what that means. The clue may be in the error message. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.