简体   繁体   English

Rails 4:response_with参数错误

[英]Rails 4: respond_with arguments error

in my rails app (v. 4.1.9) i get the following error after a create action: 在我的Rails应用程序(4.1.9版)中,创建操作后出现以下错误:

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

Here is my code: 这是我的代码:

routes.rb 的routes.rb

scope module: :explore do
  resources :questions
end

questions_controller.rb 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

I also tried respond_with question_path and redirect_to question_path but always the same error. 我也尝试了respond_with question_pathredirect_to question_path respond_with question_path ,但是总是相同的错误。

Any ideas? 有任何想法吗?

I found my problem. 我发现了问题。 In a helper I included ActionView::Helpers::UrlHelper . 在帮助器中,我包含了ActionView::Helpers::UrlHelper After removing this, respond_with and redirect_to works fine. 删除此选项后, respond_withredirect_to可以正常工作。

Try this 尝试这个

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