使用Appscript和Rails

时间:2016-07-17 06:35:35

标签: ruby-on-rails macos appscript

我已经在我的Rails项目中安装了rb-scpt gem并运行了bundle。宝石是来自rb-appscript的一个分支。

从终端运行时,以下程序有效:

<!doctype html>
<html>
  <head>
  <link rel="stylesheet" type="text/css" href="Testing.css">
  <script>
  function addNew(){
  var datatwo = localStorage.datatwo;
  var newData = document.createTextNode(datatwo);
  var hello = document.createElement("th");
  hello.appendChild(newData);
  document.getElementById("Questions").appendChild(hello);
}
  </script>
  </head>

  <body>
    <div id="Addnew">
      <button onclick="addNew()" id ="AddNewButton">Add new </button>
    </div>
    <h1>This is Page 1 </h1>
    <table>
      <tr id="Questions">
        <th>What is my Name</th>
        <th>What is his name</th>

      </tr>

      <tr>
        <td>Justin</td>
        <td>James</td>
      </tr>
    </table>
        <nav>
            <div id="footerPages">

                  <ul>
                        <li><p>Page 1 of 3</p></li>
                        <li><a href=""> < Prev </a></li>
                        <li><a href="#"> 1 </a></li>
                        <li><a href="Testing2.html"> 2 </a></li>

                        <li><a href="#"> 3 </a></li>
                        <li><a href="#"> 4 </a></li>
                        <li><a href="#"> 5 </a></li>
                        <li><a href="#"> 6 </a></li>
                        <li><a href="#"> 7 </a></li>
                          <li><a href="Testing2.html"> Next ></a></li>
                 </ul>
            </div>
          </nav>




  </body>

</html>

我创建了一个控制器来做同样的事情:

<!doctype html>
<html>
  <head>
  <link rel="stylesheet" type="text/css" href="Testing.css">
  <script>
   function addNew(){
     var data = prompt("What is your question?");
     localStorage.datatwo = data;

   }
  </script>
  </head>

  <body>
    <div id="Addnew">
      <button onclick="addNew()" id ="AddNewButton">Add new </button>
    </div>
    <h1>HI THIS IS PAGE 2</h1>
    <table>
      <tr id="Questions">
        <th>What is my Name</th>
        <th>What is his name</th>

      </tr>

      <tr>
        <td>Justin</td>
        <td>James</td>
      </tr>
    </table>
        <nav>
            <div id="footerPages">

                  <ul>
                        <li><p>Page 1 of 3</p></li>
                        <li><a href="Testing.html"> < Prev </a></li>
                        <li><a href="Testing.html"> 1 </a></li>
                        <li><a href="#"> 2 </a></li>
                        <li><a href="#"> 3 </a></li>
                          <li><a href="#"> Next ></a></li>
                 </ul>
            </div>
          </nav>




  </body>

</html>

当我运行它时,我在第3行得到错误:

#!/usr/bin/env ruby

# List names of playlists in iTunes.

require "rb-scpt"

itu = Appscript.app("iTunes")
p itu.sources[1].user_playlists.name.get

我错过了什么?我确信这很简单。

我正在使用RubyMine作为我的IDE。当我输入:: Appscript。时,我开始从IDE获取代码提示,说源是Appscript。这是gem中rb-scpt.rb的摘录:

class ItunesController < ApplicationController
  def play
    itu = ::Appscript.app('iTunes')
    play_list = itu.sources[1].user_playlists.name.get
    render text(play_list)
  end
end

1 个答案:

答案 0 :(得分:0)

尝试使用以下行itu = ::Appscript.app("iTunes")