0
Railsプロジェクトにrb-scpt gemをインストールし、バンドルを実行しました。宝石は、rb-appscriptのフォークです。AppscriptをRailsで使用する
ターミナルから実行すると、次のプログラムが動作します。
#!/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
私は同じことを行うためのコントローラを作成しました:私はそれを実行すると
class ItunesController < ApplicationController
def play
itu = ::Appscript.app('iTunes')
play_list = itu.sources[1].user_playlists.name.get
render text(play_list)
end
end
は、私は、3行目のエラーが表示されます。
#<NameError: uninitialized constant ItunesController::Appscript>
何が欠けていますか?私はそれが何か簡単だと確信しています。
私はIDEとしてRubyMineを使用しています。私が:: Appscript。と入力すると、ソースからAppscriptが読み込まれたことをIDEからヒントとして得始める。これは、宝石でRB-scpt.rbからの抜粋です:
module Appscript
...
class GenericApplication < GenericReference
def initialize(app_class)
@_app_class = app_class
super(['app'])
end
def by_name(name, terms=true)
return @_app_class.by_name(name, terms)
end
def by_id(id, terms=true)
return @_app_class.by_id(id, terms)
end
def by_creator(creator, terms=true)
return @_app_class.by_creator(creator, terms)
end
def by_pid(pid, terms=true)
return @_app_class.by_pid(pid, terms)
end
def by_url(url, terms=true)
return @_app_class.by_url(url, terms)
end
def by_aem_app(aem_app, terms=true)
return @_app_class.by_aem_app(aem_app, terms)
end
def current(terms=true)
return @_app_class.current(terms)
end
end
#######
AS_App = Appscript::GenericApplication.new(Application)
AS_Con = Appscript::GenericReference.new(['con'])
AS_Its = Appscript::GenericReference.new(['its'])
######################################################################
# REFERENCE ROOTS
######################################################################
# public (note: Application & GenericApplication classes may also be accessed if subclassing Application class is required)
def Appscript.app(*args)
if args == []
return AS_App
else
return AS_App.by_name(*args)
end
end
私は同じエラーを取得を使用してみてください。それを見ていただきありがとうございます。 – curt
あなたのソリューションは問題を解決しませんでしたが、それは私をさらに進化させました。呼び出しによって、アプリスクリプトコードに呼び出されます。検査するための呼び出しが動作します。 – curt