簡體   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