ruby-on-rails Rails 4:带有参数的response_error

z2acfund  于 2023-02-26  发布在  Ruby
关注(0)|答案(2)|浏览(159)

在我的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
    • 问题_控制器. 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,但总是同样的错误。
有什么想法吗?

soat7uwm

soat7uwm1#

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

lhcgjxsq

lhcgjxsq2#

试试这个

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

相关问题