コメントはAJAXで投稿されたコメントページを作成しようとしています。私はRails 3を使用しています。私の設定ではform_forブロックに設定しています:remote => true。 Chromeデベロッパーツールを見ると、サーバーがcreate.js.erbというページをtext/javascriptとして返すが、javascriptは実行されていないことがわかります。create.js.erbがレンダリングされないのはなぜですか?
commentable_controller
def create
@commentable = Commentable.new
@commentable.body = params[:body]
@commentable.user = current_user
if @commentable.save
respond_to do |format|
format.js
end
end
end
create.js.erb
alert("hello world");
show.html.haml
#feed
=render :partial => "commentable/commentable", :collection => @commentables
-form_tag('/commentable/create', :remote => true) do
=hidden_field_tag :game_id, @game.id
=text_area_tag :body, nil, :rows => 3, :value => "160 Characters", :id => 'new_message'
=submit_tag "Post"
編集:
この以上に見た後、私がすることができますそのrを参照してくださいequestはHTMLとして入力されていますが、これは正しくありません。どうやらこれはRails 3が使っているプロトタイプのバージョンと関係があります... wtf rails
私が考えることができるのは、jquery-mobileが何らかの理由でcreate.js.erbのjavascriptに干渉しているということだけです。 – Teddy
:remote => true? – efoo
レール3についてはわかりませんが、以前のバージョンのレールでは、ajaxリクエストが処理されたときにjavascriptがロードされません。手動でJavaスクリプトを組み込むコードを書いています..... – Anubhaw