预计响应会成功,但结果是 302
我有以下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
在我的终端上rake paths
给我:
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"
当我从终端运行 rake 并使用以下 posts_test_controller 内容时:
test "should get myarticles signed in" do
get :myarticles
assert_response :success
end
我收到有关重定向到的失败信息
Expected response to be a <:success>, 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 routes
gives me:
myarticles_articles GET /articles/myarticles(.:format) {:action=>"myarticles", :controller=>"articles"}
my config/routes.rb is
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 on my browser I navigate to
http://127.0.0.1:3000/articles/myarticles
I have the 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 articles_test_controller content:
test "should get myarticles signed in" do
get :myarticles
assert_response :success
end
I get the failure
Expected response to be a <:success>, but was <302>
I read about redirect to but I can't seem to fix that issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要调试丢失的模板问题,您可以尝试以下操作:
?
关于您的规格失败,您可能需要在测试中拥有当前用户会话,否则它会认为您是已注销的用户并将您重定向到登录页面。我没有使用过 Devise,但看起来自述文件在“测试助手”下有一些建议:https://github。 com/plataformatec/devise
To debug your missing template issue, could you try something like:
?
Regarding your specs failure, you likely need to have a current user session in your tests, otherwise it thinks you're a logged out user and redirects you to a login page. I haven't used Devise but it looks like the README has some suggestions under "Test Helpers" : https://github.com/plataformatec/devise