2012-02-16 5 views
2

하였다 I가 다음 articles_controller :예상 응답은 성공하지만, 302

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

내 설정/routes.rb이

입니다 : 내 터미널 rake routes

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 

나를 준다

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 

로 이동합니다

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

:

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 함량 터미널에서 레이크를 실행할 때 나는 실패한다.

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 Helper"아래에 몇 가지 제안이있는 것 같습니다 : https://github.com/plataformatec/devise

+0

다음과 같이 변경합니다 : on articles_controller.rb put after respond_to do | format | -> format.html {render 'myarticles'} 및 articles_controller_test.rb 테스트 후 put "myarticles가"do -> sign_in students (: student2)에 로그인해야 함 (테스트/fixtures/students.yml student2에 있음) . /app/views/articles/myarticles.html.erb 경로에서 내 템플릿을 복사하여 /app/views/myarticles.html.erb에 복사하지만 설명이있는 오류가 발생했습니다. ActionView :: MissingTemplate : 누락 된 템플릿 기사/myarticles with {: 처리기 => [: erb, : rjs ... –