Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorpweil
     
    If I use the link_to helper, and add an id for the anchor tag, I also get an unwanted 'onclick' attribute.

    <%= link_to 'Inventory', {:action=>'index'}, :id=>'goInv' %>

    returns

    <a href="/inventory/resource/" id="goInv" onclick="">Inventory</a>

    How do I get rid of the onclick? It must be sort of default. I've tried reading the info about link_to, but can't find anything about this.
    • CommentAuthorKaste
     

    hm, thats a default in

    UrlHelper::convert_options_to_javascript($html_options);
    

    It's called because you set 'id=>...' as a html-option. You could provide a patch. ;-)

    • CommentAuthorpweil
     
    Hmmm, ok. Seems like it ought to be an option instead of a default. What is the suggested way for overriding this? Place a 'new' link_to function (minus the line $this->convert_options_to_javascript($html_options) in application_controller? Or do I need to use a function with a different name?
    • CommentAuthorpweil
     
    OK, the only thing I could do that seems to work is to modify UrlHelper::link_to. Is there no way to override built-in functions other than to modify the original? In any case, what I did was to I adda loop that checks for any javascript options. This may not be the best way to do this; if anyone knows of a better, more efficient method, I'm all ears:

    function link_to($name = null, $options = array(), $html_options = array(), $parameters_for_method_reference = null)
    {
    if (!empty($html_options)) {

    // foreach loop added by pw to make javascript an option, not a default

    foreach (array('confirm', 'popup', 'post') as $option){
    if (isset($html_options[$option])) {
    $this->convert_options_to_javascript($html_options);
    }
    }
    // end modification

    $tag_options = TagHelper::_tag_options($html_options);
    }
    else{
    $tag_options = null;
    }
    $url = is_string($options) ? $options : $this->url_for($options, $parameters_for_method_reference);
    $name = empty($name) ? $url : $name;
    return "<a href=\"{$url}\"{$tag_options}>{$name}</a>";
    }