Rails 4: respond_with 参数错误

Rails 4: respond_with arguments error

在我的 rails 应用程序 (v. 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,但总是出现同样的错误。

有什么想法吗?

试试这个

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

我发现了我的问题。在一个助手中,我包含了 ActionView::Helpers::UrlHelper。删除它后,respond_withredirect_to 工作正常。