How to Make a Ruby Program That Prints a Document

The Ruby on Rails language gives developers the ability to create dynamic, interactive Web pages on their blogs and websites. If you want to give users the option to print documents, you must create a button that opens a print dialogue window. You create dynamic JavaScript code in the Ruby language and assign the button to the JavaScript function for your printing procedure.

Instructions

    • 1

      Launch your Ruby on Rails editor and open the Internet project for your website. Double-click the code file you want to use to create the print function.

    • 2

      Create the dynamic JavaScript code. The following code creates a script that gives users the option to print documents:

      def print_script
      @print= "window.print();"
      end

    • 3

      Link the print script to a button on your Web page. The following code is an example of a button, and it shows you how to link your Ruby script to the button's "onClick" event:

      <input type="button" onclick="<% @print %>" value="Click to Print Document">

Related Searches:

References

Comments

Related Ads

Featured