1

My model:

def full_name
  "#{first_name} #{middle_name} #{last_name} #{suffix_name}".mb_chars.upcase.squeeze(' ').strip
end

My rabl template:

collection @users
attributes :id, :full_name

This is inserting an extra child named wrapped_string

[{"user":{"id":73,"full_name":{"wrapped_string":"FOO BAR"}}}]

but I need something like:

[{"user":{"id":73,"full_name":"FOO BAR"}}]

If I don't use mb_chars works great, but I must to use it. What should I do?

4

1 に答える 1

1

You need to add to_s to convert the MultiByte::Chars into a string again:

def full_name
  "#{first_name} #{middle_name} #{last_name} #{suffix_name}".mb_chars.upcase.squeeze(' ').strip.to_s
end
于 2013-01-31T18:33:56.553 に答える