0

I try to create and Display errors in Rails, I have a problem for that.

Here my code:

controller:

flash[:errors] = []
flash[:errors] << [:message => t('clubs.errors.no_contact'), :strong => new_member_params[:email] + ': ']

view:

<% if flash[:errors].present? %>
        <% flash[:errors].each do |error| %>
        <div class="alert alert-danger">
            <a class="close" aria-hidden="true" href="#" data-dismiss="alert">×</a>
            <strong><%= error[:strong] %></strong>
            <%= error[:message] %>
        </div>
        <% end %>
    <% end %>

and I have this error :

TypeError in Clubs#members
no implicit conversion of Symbol into Integer

on this line:

<strong><%= error[:strong] %></strong>

Any idea ?

1 Answer 1

1

If you look at flash[:errors] after you do this:

flash[:errors] << [:message => t('clubs.errors.no_contact'), :strong => new_member_params[:email] + ': ']

it will probably look something like [[{message: 'no_contact'}]] because you're wrapping a hash in square brackets... Basically putting a Hash in an Array in an Array. I think what you want to do is change that line above so that you're just appending a Hash instead of a hash inside of an Array, like this:

flash[:errors] << { :message => t('clubs.errors.no_contact'), :strong => (new_member_params[:email] + ': ') }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.