繁体   English   中英

Rails 4:response_with参数错误

[英]Rails 4: respond_with arguments error

在我的Rails应用程序(4.1.9版)中,创建操作后出现以下错误:

arguments passed to url_for can't be handled. Please require routes or provide your own implementation

这是我的代码:

的routes.rb

scope module: :explore do
  resources :questions
end

questions_controller.rb

class Explore::QuestionsController < Explore::BaseController
  respond_to :html
  authorize_resource

  def create
    @question = Question.new question_params
    @question.save

    respond_with @question
  end
end

我也尝试了respond_with question_pathredirect_to question_path respond_with question_path ,但是总是相同的错误。

有任何想法吗?

我发现了问题。 在帮助器中,我包含了ActionView::Helpers::UrlHelper 删除此选项后, respond_withredirect_to可以正常工作。

尝试这个

def create
    @question = Question.new question_params
    if @question.save
        flash[:success] = "Question created!"
        redirect_to questions_path
        or 
        redirect_to :controller => 'questions', :action => 'new'
        or
        redirect_to :back
    end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM