0

Right now I'm using the following to output error messages in my Rails 3 app. This is located in the layout view under the header:

<% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %>

This works ok for most cases, but when I have a signin for, and the user enters invalid credentials, showing an error message in the header looks bad. It's to far from the form. And most sites show the error message right above the form?

How can I do that? Do you really have to specify this error block in all your views? Given how amazing rails is, I'm guessing there's some trick to make this work?

Thanks

1 Answer 1

1

If you're using form_for and passing it an instance of whatever object your form represents, it will automatically put the errors inline with the fields. You could even take that a step further and use the gem Formtastic. It takes care of building semantic HTML.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but I'm so lost here... In my User Model I have validations, in my view I have the form_for and the flash notice... Where is the controller for all this? How do I pass the errors so they output? Please help! :)
It would be great to see how to use devise with formtastic, can't seem to find any tutorials

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.