2011-07-24 2 views
1

私はRuby on Rails 3.0.9とjQuery 1.6.2を使用しています。現在表示されているファイルに表示されていないフォルダから "アクションファイルをレンダリング"したいと思います。私が持っている私のarticles_controllerファイルで現在のビューフォルダの外でアクションをレンダリングする

:記事ビューからAJAX HTTPリクエストを作る

respond_to do |format| 
    format.html { 
    # ... 
    } 
    format.js { 
    render :action => 'shared/article.js.erb' # Note the 'shared' folder 
    } 
end 

(ビューがshow.html.erbファイルであり、それはviews/articlesフォルダにあります)私は次の取得エラー:

ActionView::MissingTemplate (Missing template articles/article with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:js, :html], :locale=>[:en, :en]}... 

どうすれば解決できますか?

ログファイルは以下の通りです:

Railsの3オン
Started GET "/articles/2/article" for 127.0.0.1 at 2011-07-24 13:05:16 +0200 
    Processing by ArticlesController#article as JS 

ActionView::MissingTemplate (Missing template ActionView::MissingTemplate (Missing template articles/article with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:js, :html], :locale=>[:en, :en]}... 

答えて

1

、この動作するはずです:

render 'shared/article' 

れていない場合は、あなたが明示的に指定できます

render :template => 'shared/article' 

レンダリングの章のRails Guidesで詳細をご覧ください。

+0

'format.js {...}'にyuorコードを使用すると、 'Missing template articles/artilcle'に関する質問に同じエラーが表示されます。 – Backo

+0

respond_toを削除し、レンダリングのみを保持してください。あなたのajaxリクエストが正しいacceptヘッダーを設定していないようです。あなたのリクエストログをあなたの質問に追加すると便利です。 –

+0

HTMLリクエストとJSリクエストの両方を処理する必要があります。 – Backo

関連する問題