Rails inline Javascript and Best Practices

后端 未结 5 2089
名媛妹妹
名媛妹妹 2021-02-14 08:02

I\'m kinda new to using Rails, and an app I am working on is progressing well - however I\'m looking though the generated HTML and noticed things like...



        
5条回答
  •  南笙
    南笙 (楼主)
    2021-02-14 08:30

    This bothered me for a while and I eventually came up with a two pronged approach.

    If you are developing a web application for a closed domain, where search engine performance and javascript are not an issue, just be pragmatic and let Rails' javascript helpers do their thing.

    If you are developing for the web at large then do what Tomh sugested and code in plain html/css and then enhance onDomReady.

    If you still want to use Rails helpers like button_to_remote that use inline javascript, then code your page load handler to send an Ajax request to the server. you can then use page.replace / page.replace_html to replace your regular page elements with code returned from the helpers.

提交回复
热议问题