soffolk Zhu
2013-Jun-01 06:57 UTC
How about add a method to truncate a long text more smart?
sometimes we need to truncate a long text more smart. eg: The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic that is specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module. You can read more about Active Record in its README. to The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic that is specific to your application. I create a method content_truncate <https://github.com/zlx/content-truncate> to implementation my requirement. But it is so immature for merge into activesupport So welcome advices -- 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/msgid/rubyonrails-talk/1ceeaa22-b640-4e6a-9e94-fd3f33981fbc%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Tamara Temple
2013-Jun-01 20:30 UTC
Re: How about add a method to truncate a long text more smart?
soffolk Zhu <zlx.star-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sometimes we need to truncate a long text more smart. > > The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates > the business logic that is specific to your application. In Rails, database-backed model classes are derived > from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and > embellish these data objects with business logic methods. Although most Rails models are backed by a > database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as > provided by the Active Model module. You can read more about Active Record in its README. > > to > > The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates > the business logic that is specific to your application. > > I create a method content_truncate to implementation my requirement. But it is so immature for merge into > activesupport > > So welcome advicesI''d use it either in a validation or a callback to the model. -- 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/msgid/rubyonrails-talk/51aa59d5.a66f320a.69f8.ffffceb2%40mx.google.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
soffolk Zhu
2013-Jun-03 15:59 UTC
Re: How about add a method to truncate a long text more smart?
The truncate result is pool mostly time, so i think a more meaningful is useful 在 2013年6月2日星期日UTC+8上午4时30分12秒,tamouse写道:> > soffolk Zhu <zlx....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> wrote: > > sometimes we need to truncate a long text more smart. > > > > The Model layer represents your domain model (such as Account, > Product, Person, Post, etc.) and encapsulates > > the business logic that is specific to your application. In Rails, > database-backed model classes are derived > > from ActiveRecord::Base. Active Record allows you to present the > data from database rows as objects and > > embellish these data objects with business logic methods. Although > most Rails models are backed by a > > database, models can also be ordinary Ruby classes, or Ruby classes > that implement a set of interfaces as > > provided by the Active Model module. You can read more about Active > Record in its README. > > > > to > > > > The Model layer represents your domain model (such as Account, > Product, Person, Post, etc.) and encapsulates > > the business logic that is specific to your application. > > > > I create a method content_truncate to implementation my requirement. But > it is so immature for merge into > > activesupport > > > > So welcome advices > > I''d use it either in a validation or a callback to the model. > >-- 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/msgid/rubyonrails-talk/a77a2d68-8be2-491e-81a5-4aba40dc7bf8%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Peter
2013-Jun-04 14:57 UTC
Re: How about add a method to truncate a long text more smart?
On Saturday, June 1, 2013 1:57:58 AM UTC-5, soffolk Zhu wrote:> I create a method content_truncate<https://github.com/zlx/content-truncate> to > implementation my requirement. But it is so immature for merge into > activesupport >You might checkout truncate_html <https://github.com/hgmnz/truncate_html>and consider combining your functionality into there as options. \Peter -- 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/msgid/rubyonrails-talk/bc94865b-1dad-4270-85f4-c9415debb63f%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Tamara Temple
2013-Jun-05 00:13 UTC
Re: How about add a method to truncate a long text more smart?
soffolk Zhu <zlx.star-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The truncate result is pool mostly time, so i think a more meaningful is usefulI can''t parse this, sorry.... -- 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/msgid/rubyonrails-talk/51ae82b9.6ab3ec0a.7b56.0acc%40mx.google.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
soffolk
2013-Jun-05 00:28 UTC
Re: How about add a method to truncate a long text more smart?
I mean the result use content_truncate is more meaningful for user sorry about my poor English. On June 5, 2013 at 8:14:34 AM, Tamara Temple (tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote: soffolk Zhu <zlx.star-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The truncate result is pool mostly time, so i think a more meaningful is usefulI can''t parse this, sorry.... -- You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/eO8RZMSnCmU/unsubscribe?hl=en-US. To unsubscribe from this group and all its topics, 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/msgid/rubyonrails-talk/51ae82b9.6ab3ec0a.7b56.0acc%40mx.google.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out. -- 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/msgid/rubyonrails-talk/etPan.51ae8610.6b8b4567.f20f%40Macbook.easyread?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
soffolk
2013-Jun-05 14:43 UTC
Re: Re: How about add a method to truncate a long text more smart?
On June 4, 2013 at 10:58:25 PM, Peter (ppgengler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote: You might checkout truncate_html and consider combining your functionality into there as options. \Peter It seems use for content contains html tag, while i process for pure string without html tag -- 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/msgid/rubyonrails-talk/etPan.51af4e7a.74b0dc51.f20f%40Macbook.easyread?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Tamara Temple
2013-Jun-05 22:26 UTC
Re: How about add a method to truncate a long text more smart?
soffolk <zlx.star-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I mean the result use content_truncate is more meaningful for userSo, this would be something you''d use in a view? If so, it should go in a helper. -- 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/msgid/rubyonrails-talk/51afbb22.c74e320a.6068.ffff852d%40mx.google.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
soffolk
2013-Jun-06 00:57 UTC
Re: How about add a method to truncate a long text more smart?
more than that, you can use it to produce your summary and save it into database. I think it''s a universal function, and we need not to limit it. just expand String On June 6, 2013 at 6:27:21 AM, Tamara Temple (tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote: soffolk <zlx.star-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I mean the result use content_truncate is more meaningful for userSo, this would be something you''d use in a view? If so, it should go in a helper. -- You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/eO8RZMSnCmU/unsubscribe?hl=en-US. To unsubscribe from this group and all its topics, 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/msgid/rubyonrails-talk/51afbb22.c74e320a.6068.ffff852d%40mx.google.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out. -- 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/msgid/rubyonrails-talk/etPan.51afde86.238e1f29.f20f%40Macbook.easyread?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Tamara Temple
2013-Jun-06 02:52 UTC
Re: How about add a method to truncate a long text more smart?
soffolk <zlx.star-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> more than that, you can use it to produce your summary and save it into database. > > I think it''s a universal function, and we need not to limit it. just expand StringIf you want to, go ahead. Put it in a module, then send :include to String with your module name. If you really did not want suggestions, why did you ask for them? If you already have an answer you are settled on, why open things up? Just do it, see what you get. -- 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/msgid/rubyonrails-talk/51aff989.a870320a.7303.ffffdb33%40mx.google.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
soffolk
2013-Jun-06 05:06 UTC
Re: How about add a method to truncate a long text more smart?
On June 6, 2013 at 10:54:10 AM, Tamara Temple (tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote: If you want to, go ahead. Put it in a module, then send :include to String with your module name. If you really did not want suggestions, why did you ask for them? If you already have an answer you are settled on, why open things up? Just do it, see what you get. I am sorry about your misunderstand, Thanks for your advices. -- 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/msgid/rubyonrails-talk/etPan.51b018ee.2eb141f2.f20f%40Macbook.easyread?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.