Question

I'm using DataMapper's validations, but I can't get the error messages text :(

I tried:

@error = user.errors.first
@error = user.errors.full_messages.first
@error = user.errors.full_messages.flatten
@error = user.errors[0]

But still I get an array :(

In my template I have

- if @error
  %p.lead= @error

And I get ["This username is taken"]

If I have

- if @error
  - @error.each do |er|
    %p.lead= er

it works, but isn't there a way to send only a string to the template and it to work with the %p = @error ?

Was it helpful?

Solution

If @error is an array, which it seems to be, then that's how it will show up.

What you probably want is:

@error = user.errors.full_messages.flatten.join(', ')

Something like that will collapse it to a string. flatten returns an Array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top