Expected answer will be successful, but was 302

I have the following articles_controller:

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

on my terminal rake routesgives me:

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

my 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

and my view is in /app/views/articles/myarticles.html.erb

When in my browser I go to

http://127.0.0.1:3000/articles/myarticles

I have an error:

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"

and when I run rake from the terminal with the following contents of articles_test_controller:

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

I get rejected

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

I read about redirection, but I cannot fix this problem.

+3
source share
1 answer

To debug the missing template issue, you could try something like:

format.html { render 'myarticles' }

?

, , , , . Devise, , README "Test Helpers": https://github.com/plataformatec/devise

+1

All Articles