gpt4 book ai didi

ruby-on-rails - 预期响应会成功,但结果为 302

转载 作者:行者123 更新时间:2023-12-04 18:23:00 34 4
gpt4 key购买 nike

我有以下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 routes给我:
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"

当我使用以下文章_test_controller 内容从终端运行 rake 时:
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' }

?

关于您的规范失败,您可能需要在测试中拥有当前用户 session ,否则它会认为您是已注销的用户并将您重定向到登录页面。我没有使用过 Devise,但看起来 README 在“测试助手”下有一些建议: https://github.com/plataformatec/devise

关于ruby-on-rails - 预期响应会成功,但结果为 302,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9315992/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com