nobosh
2010-Oct-10 20:15 UTC
Rails - truncate - is not behaving--- Using a var returned from the model
Here is the truncate code I''m using:
<%= truncate(teammember.user.full_name, :length => 8)%>
teammember.user.full_name returns names like:
- Steve Jobs
- Larry Oracle
- James Bond
- Dhandar Kentavolv
Butall the truncate is doing is returning:
- Steve Jobs...
- Larry Oracle...
- James Bond...
- Dhandar Kentavolv...
The user.full_name is not a field in the DB but a helper in the user
model, which might be the issue.?
def full_name
if !fname.nil? && !fname.empty?
[fname, lname].join(" ")
else
[''User'', id].join(" ")
end
end
I then tried:
<%= truncate("Once upon a time in a world far far away", :length
=>
1)%>
And that returns: Once... and not O...
Any ideas? thanks!
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
rajeevsharma86
2010-Oct-11 04:37 UTC
Re: Rails - truncate - is not behaving--- Using a var returned from the model
i am not sure but try this
truncate("Once upon a time in a world far far away", :length => 17,
:separator => '' '') or
write the outputs examples which you want to come
On Mon, Oct 11, 2010 at 1:45 AM, nobosh
<bhellman1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Here is the truncate code I''m using:
>
> <%= truncate(teammember.user.full_name, :length => 8)%>
>
> teammember.user.full_name returns names like:
> - Steve Jobs
> - Larry Oracle
> - James Bond
> - Dhandar Kentavolv
>
> Butall the truncate is doing is returning:
> - Steve Jobs...
> - Larry Oracle...
> - James Bond...
> - Dhandar Kentavolv...
>
>
> The user.full_name is not a field in the DB but a helper in the user
> model, which might be the issue.?
>
> def full_name
> if !fname.nil? && !fname.empty?
> [fname, lname].join(" ")
> else
> [''User'', id].join(" ")
> end
> end
>
> I then tried:
> <%= truncate("Once upon a time in a world far far away",
:length =>
> 1)%>
> And that returns: Once... and not O...
>
>
> Any ideas? thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
Thanks:
Rajeev sharma
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
nobosh
2010-Oct-11 07:14 UTC
Re: Rails - truncate - is not behaving--- Using a var returned from the model
strange. that didn''t work...Or have any effect on the output...
The output examples I want:
<%= truncate("#{teammember.user.full_name}", :length => 5) %>
When full_name return "John Legend"
Should return: John...
Example 2, full_name = Howard Smith
Should return: Howar...
Very strange bug this is.... Is the truncate method reliable? thanks
On Oct 10, 9:37 pm, rajeevsharma86
<rajeevsharm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> i am not sure but try this
>
> truncate("Once upon a time in a world far far away", :length
=> 17,
> :separator => '' '') or
>
> write the outputs examples which you want to come
>
>
>
>
>
> On Mon, Oct 11, 2010 at 1:45 AM, nobosh
<bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Here is the truncate code I''m using:
>
> > <%= truncate(teammember.user.full_name, :length => 8)%>
>
> > teammember.user.full_name returns names like:
> > - Steve Jobs
> > - Larry Oracle
> > - James Bond
> > - Dhandar Kentavolv
>
> > Butall the truncate is doing is returning:
> > - Steve Jobs...
> > - Larry Oracle...
> > - James Bond...
> > - Dhandar Kentavolv...
>
> > The user.full_name is not a field in the DB but a helper in the user
> > model, which might be the issue.?
>
> > def full_name
> > if !fname.nil? && !fname.empty?
> > [fname, lname].join(" ")
> > else
> > [''User'', id].join("
")
> > end
> > end
>
> > I then tried:
> > <%= truncate("Once upon a time in a world far far away",
:length =>
> > 1)%>
> > And that returns: Once... and not O...
>
> > Any ideas? thanks!
>
> > --
> > You received this message because you are subscribed to the Google
Groups
> > "Ruby on Rails: Talk" group.
> > To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
> >
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib
e@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> Thanks:
> Rajeev sharma
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Oct-11 07:36 UTC
Re: Rails - truncate - is not behaving--- Using a var returned from the model
On Oct 11, 8:14 am, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> strange. that didn''t work...Or have any effect on the output... >Then maybe the code you''re editing isn''t actually the code that''s being run. Stick a breakpoint in your code and follow the flow when truncate is called. Fred> The output examples I want: > > <%= truncate("#{teammember.user.full_name}", :length => 5) %> > > When full_name return "John Legend" > > Should return: John... > > Example 2, full_name = Howard Smith > > Should return: Howar... > > Very strange bug this is.... Is the truncate method reliable? thanks > > On Oct 10, 9:37 pm, rajeevsharma86 <rajeevsharm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > i am not sure but try this > > > truncate("Once upon a time in a world far far away", :length => 17, > > :separator => '' '') or > > > write the outputs examples which you want to come > > > On Mon, Oct 11, 2010 at 1:45 AM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Here is the truncate code I''m using: > > > > <%= truncate(teammember.user.full_name, :length => 8)%> > > > > teammember.user.full_name returns names like: > > > - Steve Jobs > > > - Larry Oracle > > > - James Bond > > > - Dhandar Kentavolv > > > > Butall the truncate is doing is returning: > > > - Steve Jobs... > > > - Larry Oracle... > > > - James Bond... > > > - Dhandar Kentavolv... > > > > The user.full_name is not a field in the DB but a helper in the user > > > model, which might be the issue.? > > > > def full_name > > > if !fname.nil? && !fname.empty? > > > [fname, lname].join(" ") > > > else > > > [''User'', id].join(" ") > > > end > > > end > > > > I then tried: > > > <%= truncate("Once upon a time in a world far far away", :length => > > > 1)%> > > > And that returns: Once... and not O... > > > > Any ideas? thanks! > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > Thanks: > > Rajeev sharma-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Andrey Chernih
2010-Nov-12 13:27 UTC
Re: Rails - truncate - is not behaving--- Using a var returned from the model
Actually, the :separator parameter is only supported by the newer version of Rails. For instance, the :separator has no effect in Rails 2.3.4. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.