-1

これは一般的な質問ではないかもしれませんが、この機能が必要です。

私のコントローラーではApplicationLike.js、次の名前の JavaScript ファイルをレンダリングしたいと考えています。

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require rr/lib/jquery-1.7.2.min.js
//= (other requires)

そして、コントローラーにはinjectアクションがあります。プリコンパイル済みの CONTENTS をレンダリングしたいのは、次ApplicationLike.jsの属性として使用されるためです。src

<script src="//localhost:3000/app/inject.js/"></script>

上記の ALREADY-EXISTINGタグの属性に純粋な JavaScript コンテンツが必要なだけなので、構文エラーの原因となるjavascript_include_tagjavascript タグが含まれるため、は使用できません。<script type="text/javascript"></script>src<script>

皆さんが私が話していることを理解しているかどうかはわかりません。

私は5時間か8時間以上グーグルで検索しましたが、うまくいきませんでした。

Rails 3.2 と Ruby 1.9.3 を使用しています

注:redirect_to /assets/ApplicationLike.js動作しますが、動的な Ruby 変数 (たとえばcurrent_user.id) を含む JavaScript コードの行をさらにレンダリングする必要があります。

しかし、もちろん、先ほど述べたように、JavaScript コードinject.js.erbの内容とそれ以上の行の両方を含むと呼ばれるビューを使用できます。プリコンパイルされたJavaScript ファイルApplicationLike.jsの内容だけをレンダリングする方法がわかりません。ApplicationLike.js

4

1 に答える 1