2012-02-16 12 views
2

私は、次のarticles_controllerていました。私のターミナルrake routes成功されることが予想応答が、302

def myarticles 
    @myarticles = current_student.articles.all 
    respond_to do |format| 
     format.html 
     format.xml { render :xml => @myarticles } 
    end 
end 

def create 
    @article = current_student.articles.new(params[:article]) 
    respond_to do |format| 
    if @article.save 
     format.html { redirect_to(@article, :notice => 'επιτυχώς.') } 
     format.xml{render:xml => @article, :status => :created, :location => @article} 
    else 
     format.html { render :action => "new" } 
     format.xml { render :xml => @article.errors, :status => :unprocessable_entity} 
    end 
    end 
end 

は私を与える:

myarticles_articles GET /articles/myarticles(.:format) {:action=>"myarticles", :controller=>"articles"} 

私のconfig/routes.rbをが

です
Sample::Application.routes.draw do 
    devise_for :students 

    resources :articles do 
    collection do 
     get 'about' 
     get 'all' 
     get 'myarticles' 
    end 
end 

root :to => 'articles#index' 
end 

と私の見解は/app/views/articles/myarticles.html.erbにあります

私のブラウザで私がエラーしてい

http://127.0.0.1:3000/articles/myarticles 

に移動した場合:

Template is missing 

Missing template articles/myarticles with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/home/panagiotis/projects/sample/app/views", "/home/panagiotis/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.5.3/app/views" 

と私は、次のarticles_test_controllerコンテンツと端末から熊手を実行します。

test "should get myarticles signed in" do 
    get :myarticles 
    assert_response :success 
end 

を私は失敗を得る

Expected response to be a <:success>, but was <302> 

私はリダイレクトについて読んだが、私はその問題を解決できないようだ。

format.html { render 'myarticles' } 

+0

ファイルmyarticles.html.erbのプロパティで、私は所有者であり、読み書きアクセス権があります。 –

+0

私はばかです。ここにwtite myarticlesとディレクトリにmyariclesを書いてください。ただ信じられない! –

答えて

1

は、あなたのような何かを試すことができ、あなたの不足しているテンプレートの問題をデバッグするには?

スペックの失敗については、テストで現在のユーザーセッションが必要な可能性があります。それ以外の場合は、ログアウトしたユーザーだと思ってログインページにリダイレクトします。私はDeviseを使用していませんが、READMEには "Testヘルパー"の下にいくつかの提案があります。https://github.com/plataformatec/devise

+0

私はこの変更を行います:on articles_controller.rb put after respond_to do | format | - > format.html {レンダリング 'myarticles'}とテスト後のput articles_controller_test.rbは "do - > sign_in students(:student2)でmyarticlesをサインインする必要があります(私はテスト/フィクスチャ/ students.yml student2を持っています) 。 /app/views/articles/myarticles.html.erbのパスから/app/views/myarticles.html.erbにテンプレートを貼り付けてコピーしますが、説明でエラー(失敗から)が発生しました。ActionView :: MissingTemplate:テンプレート記事がありません/ myarticles with {:ハンドラー=> [:erb、:rjs ... –

関連する問題