0

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

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

这是我的代码:

路线.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但总是同样的错误。

有任何想法吗?

4

2 回答 2

2

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

于 2015-02-18T07:56:36.837 回答
0

尝试这个

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
于 2015-02-18T06:51:02.090 回答