Forum: Ruby on Rails Pagination ...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A71728118f219c95758cea1af0c4845c?d=identicon&s=25 weirdmonkey (Guest)
on 2006-03-29 23:36
Hey,

I have a CMS I am building right now and I would like to my articles to
split in many pages.

Here is what I want to do:

Once the article reaches 150 words or so it create a link to Page 2 of
the article and, on page 2, it displays the rest of the article...


How can I do that ?
(note that you explain this to a beginner :)

Thank you!
Bcef7e1dee27bd486dae324e0199fe34?d=identicon&s=25 Jeremy Cowgar (Guest)
on 2006-03-30 02:01
(Received via mailing list)
Weirdmonkey,

I will not speak for everyone, but I'd rather see your answer at
least addressed than go unanswered. Your question is very vague and
could be implemented more ways than members on this list.

You admit that you are a beginner, so I would study up a bit on your
string routines and begin to design and implement this system with
your own ideas, then when you come up against a specific problem, ask
the list. It will be much more responsive. This is also the only way
you will really learn.

I am not speaking out of criticism, but just trying to help you use
the list to it's best potential and also further your development
skills. It seems like your question is almost, how do I build a CMS
system? Maybe I have missed the main intent of the question, and if
so, maybe if you restate it others will understand it better as well
as myself.

Jeremy
A71728118f219c95758cea1af0c4845c?d=identicon&s=25 weirdmonkey (Guest)
on 2006-03-30 02:46
Jeremy,

I understand that my question my be a little vague.

Here are more details:

It is a website for books summary

I build a scaffold to be able to enter new summaries with ease.

I call the summary in the view using <%= book.summary %> and would like
to implement the truncate method to it.
(http://api.rubyonrails.com/classes/ActionView/Help...)

What I would like to do is:

-If the # of the number of words exceed 200 for example, it will create:
       Part1 ---> word 1 to word 200
       Part2 ---> word 201 to 400
       Part3 ---> word 401 to ...
       etc...

If the number of words in Part 1 exceeds 200 words, it will place a link
to Part 2 at the bottom and so on...

I hope it clearer for you now :)

Thank you!
7f023e9ef20f259eebbda8f5d7a88d6b?d=identicon&s=25 Ben and Kaz Askins (Guest)
on 2006-03-30 03:20
(Received via mailing list)
I think you'll want to implement this back in your model.  So rather
than
using <%= book.summary => in your view you'll use <%=
book.summary_page(1)
=> <%= book.summary_page(2) => etc...

book.summary_page(n) will get the appropriate chunk of text for the
current
page.  Try something like that and see how you travel.

cheers,
Ben
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-30 10:27
(Received via mailing list)
Ben and Kaz Askins wrote:
> I think you'll want to implement this back in your model.  So rather
> than using <%= book.summary => in your view you'll use <%=
> book.summary_page(1) => <%= book.summary_page(2) => etc...
>
> book.summary_page (n) will get the appropriate chunk of text for the
> current page.  Try something like that and see how you travel.
>
I tried something a little like that a couple of projects ago.  Where I
ended up having problems was how to deal with HTML tags in the text.  I
ended up with a separate Page model, and just let the users do the
splitting in the end.  Much simpler :-)
A71728118f219c95758cea1af0c4845c?d=identicon&s=25 weirdmonkey (Guest)
on 2006-03-30 23:58
Alex Young wrote:
> Ben and Kaz Askins wrote:
>> I think you'll want to implement this back in your model.  So rather
>> than using <%= book.summary => in your view you'll use <%=
>> book.summary_page(1) => <%= book.summary_page(2) => etc...
>>
>> book.summary_page (n) will get the appropriate chunk of text for the
>> current page.  Try something like that and see how you travel.
>>
> I tried something a little like that a couple of projects ago.  Where I
> ended up having problems was how to deal with HTML tags in the text.  I
> ended up with a separate Page model, and just let the users do the
> splitting in the end.  Much simpler :-)

Hi Alex,

I don't get it, can you explain further ?
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-31 10:11
(Received via mailing list)
weirdmonkey wrote:
>> ended up having problems was how to deal with HTML tags in the text.  I
>> ended up with a separate Page model, and just let the users do the
>> splitting in the end.  Much simpler :-)
>
> Hi Alex,
>
> I don't get it, can you explain further ?
>
Sure.

Because splitting a long body of text reliably and well is hard to get
right (you don't want to split in the middle of a sentence, you don't
want to leave dangling sentences, you can't break markup, images might
want to stay on the same page as a specific piece of text, and so on),
don't store the text in a single field in the Book model.  Rather, do
something like this:

create table books (
   id int not null auto_increment primary key,
   title text
   -- whatever else you need here...
);
create table pages (
   id...
   book_id int,
   position int,
   content text
   -- whatever else you need here...
);

Then your models could look like this:

class Book < ActiveRecord::Base
   has_many :pages, :order => "position", :dependent => :delete
end
class Page < ActiveRecord::Base
   belongs_to :book
   acts_as_list :scope => :book
end

Now, in your interface, you can allow the users to create pages as they
need them, putting the breaks where it makes sense in the text.  You can
still validate new pages as being shorter than a given limit if you want
to, but there's no need to do any more than that.  I've found that the
users I deal with are fairly happy to do things that way.

Hope this helps...
This topic is locked and can not be replied to.