This must be really simple but I have looked everywhere. I have a <%= item.description -% in my view and I want to trim it to 10 words. The description can be long and I want to trim this in my preview? -- Posted via http://www.ruby-forum.com/.
There may be a better way, but "dassdfasdfs"[0..10] mark On 4/27/06, James Whittaker <jmwhittaker@gmail.com> wrote:> > This must be really simple but I have looked everywhere. > > I have a <%= item.description -% in my view and I want to trim it to 10 > words. > > The description can be long and I want to trim this in my preview? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060427/2568fd6b/attachment.html
"Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. From the Ajax in the view, to the request and response in the controller, to the domain model wrapping the database, Rails gives you a pure-Ruby development environment. To go live, all you need to add is a database and a web server.".split[1..10].join(" ")
On 4/27/06, James Whittaker <jmwhittaker@gmail.com> wrote:> This must be really simple but I have looked everywhere. > > I have a <%= item.description -% in my view and I want to trim it to 10 > words. > > The description can be long and I want to trim this in my preview?item.description.split[0..9].join " " It blows away whitespace like extra spaces and carriage returns, but that wouldn''t have mattered in a view anyway so it should be fine. -- James
Mathieu Chappuis wrote:> "Rails is a full-stack framework for developing database-backed web > applications according to the Model-View-Control pattern. From the > Ajax in the view, to the request and response in the controller, to > the domain model wrapping the database, Rails gives you a pure-Ruby > development environment. To go live, all you need to add is a database > and a web server.".split[1..10].join(" ")Thanks, I knew it would be simple! Brain hurts! -- Posted via http://www.ruby-forum.com/.
> and a web server.".split[1..10].join(" ")Oups : [0..9]
Or [0...10] On 4/27/06, Mathieu Chappuis <mathieu.chappuis.lists@gmail.com> wrote:> > and a web server.".split[1..10].join(" ") > > Oups : [0..9] > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >