ruby - Error calling Javascript in Camping App -
i want learn webapps. decided learn doing , chose start simple camping (i). small & (ii). know ruby.
i think comfortable html , css side of things , using mab. decided step , add javascript fails work. here offending code snippet view:
div.image link :rel => 'stylesheet', :href => 'styles.css' script :type =>"text/javascript", :src => 'display_date.js' # hash argument go @ end. button 'display date', :type => "button", :onclick => "displaydate" end
the javascript file looks this:
function displaydate() { document.getelementbyid("demo").innerhtml=date(); }
when click 'display date' button on screen firefox webconsole reports
-- [18:32:46.762] referenceerror: displaydate not defined
it not work on ie either. camping file , javascript file in same directory. please advise. result better adding javascript inline results in stack error, can live without inline js handy know how code also.
i'm new camping , ruby too, may horrible. works though ;)
give controllers module route serve display_date.js client:
class myjs < r '/display_date\.js' js = file.read('display_date.js') def @headers['content-type'] = 'application/javascript; charset=utf-8' js end end
call displaydate function, parens: :onclick => displaydate()
.
Comments
Post a Comment