Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorbhembree
     
    Hi All,

    I am trying to do error checking on a form. In the controller I have a function that checks or various errors and adds them to the attributes when they are found using the addError() method. In the form, I can display the errors using the get_errors_for() method but I want to customize the error message so that doesn't quite work for me.

    I tried using the example from the How to do Validation page at this site like the example below:

    {?Post.errors}
    The post couldn't be saved due to these errors:
    <ul>
    {loop Post.errors}
    <li>{error}</li>
    {end}
    </ul>
    {end}

    This just ends up displaying the word "Array" for each error message. If instead of using {error} in the loop, I use {error_loop_key) then I get the key displayed (which in my case is the attribute that I assigned the error message to). I never could figure out how to get access to the value associated with the key. Is there a Sintag like {error_loop_value}?

    What I finally ended up doing to get this to work the way I wanted to was just put the whole error message in the attribute field for the addError() method and then using the Sintag {error_loop_key). this seems a little kludgy to me. Is there a better way?

    Thanks

    Barry
    • CommentAuthorKaste
     

    I think this is wrong and misleading in the wiki. IMHO you should write a helper-function for that.

    otherwise, since we can have multiple errors per attribute (=key) you just have to loop through the {error}. a double for-each, you know.

    I think this is kludgy as you said. so move_to => helper

    BTW you've seen

    <%= error_messages_for 'Post' %>
    

    ? maybe you have an idea to improve/factor/patternize this method? (its in the active_record_helper.php)