Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Re: [Rails] How about add a method to truncate a long text more smart?

82 views
Skip to first unread message

Tamara Temple

unread,
Jun 1, 2013, 4:30:12 PM6/1/13
to rubyonra...@googlegroups.com
soffolk Zhu <zlx....@gmail.com> 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.

soffolk Zhu

unread,
Jun 3, 2013, 11:59:38 AM6/3/13
to rubyonra...@googlegroups.com
The truncate result is pool mostly time, so i think a more meaningful is useful

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

Peter

unread,
Jun 4, 2013, 10:57:22 AM6/4/13
to rubyonra...@googlegroups.com
On Saturday, June 1, 2013 1:57:58 AM UTC-5, soffolk Zhu wrote:

I create a method content_truncate to implementation my requirement. But it is so immature for merge into activesupport

 You might checkout truncate_html and consider combining your functionality into there as options.

\Peter

Tamara Temple

unread,
Jun 4, 2013, 8:13:43 PM6/4/13
to rubyonra...@googlegroups.com
soffolk Zhu <zlx....@gmail.com> wrote:
> The truncate result is pool mostly time, so i think a more meaningful is useful

I can't parse this, sorry....

soffolk

unread,
Jun 4, 2013, 8:28:00 PM6/4/13
to rubyonra...@googlegroups.com

I mean the result use content_truncate is more meaningful for user


sorry about my poor English.

--
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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
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

unread,
Jun 5, 2013, 10:43:06 AM6/5/13
to rubyonra...@googlegroups.com



On June 4, 2013 at 10:58:25 PM, Peter (ppge...@gmail.com) 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

Tamara Temple

unread,
Jun 5, 2013, 6:26:41 PM6/5/13
to rubyonra...@googlegroups.com
soffolk <zlx....@gmail.com> 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.

soffolk

unread,
Jun 5, 2013, 8:57:42 PM6/5/13
to rubyonra...@googlegroups.com

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

--
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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Tamara Temple

unread,
Jun 5, 2013, 10:52:56 PM6/5/13
to rubyonra...@googlegroups.com
soffolk <zlx....@gmail.com> 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.

soffolk

unread,
Jun 6, 2013, 1:06:54 AM6/6/13
to rubyonra...@googlegroups.com



On June 6, 2013 at 10:54:10 AM, Tamara Temple (tamous...@gmail.com) 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.

Reply all
Reply to author
Forward
0 new messages