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

soffolk Zhu [email protected] wrote:

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.

The truncate result is pool mostly time, so i think a more meaningful is
useful

在 2013年6月2日星期日UTC+8上午4时30分12秒,tamouse写道:

On Saturday, June 1, 2013 1:57:58 AM UTC-5, soffolk Zhu wrote:

I create a method content_truncatehttps://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_htmland
consider combining your functionality into there as options.

\Peter

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 T. ([email protected])
wrote:
soffolk Zhu [email protected] wrote:

The truncate result is pool mostly time, so i think a more meaningful is useful

I can’t parse this, sorry…


You received this message because you are subscribed to a topic in the
Google G. “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
[email protected].
To post to this group, send email to [email protected].
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 Zhu [email protected] wrote:

The truncate result is pool mostly time, so i think a more meaningful is useful

I can’t parse this, sorry…

soffolk [email protected] wrote:

I mean the result use content_truncate is more meaningful for user

So, this would be something you’d use in a view? If so, it should go in
a helper.

On June 4, 2013 at 10:58:25 PM, Peter ([email protected]) 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

more than that, you can use it toproduce your summary and save it into
database.

I think it’s auniversal function, and we need not to limit it.
justexpand String

On June 6, 2013 at 6:27:21 AM, Tamara T. ([email protected])
wrote:
soffolk [email protected] wrote:

I mean the result use content_truncate is more meaningful for user

So, 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 G. “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
[email protected].
To post to this group, send email to [email protected].
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 [email protected] 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
String

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.

On June 6, 2013 at 10:54:10 AM, Tamara T. ([email protected])
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 yourmisunderstand, Thanks for your advices.