0

从属于优惠的旅行中,我正在尝试渲染使用 mail_form gem 生成的表单。
但我收到一条错误消息:
*undefined method `model_name' for NilClass:Class*

旅行/表演

= render :partial => '/question_forms/form', :question_form => @question_form

任何提示如何得到这个?我尝试将 question_form 模型作为旅行的关联,但它不起作用。

这是 question_forms_controller 默认代码:

class QuestionFormsController < ApplicationController
  def new
    @question_form = QuestionForm.new
  end

  def create
    begin
        @question_form = QuestionForm.new(params[:question_form])
        @question_form.request = request
        if @question_form.deliver
          flash.now[:notice] = 'Thank you for your message!'
        else
          render :new
        end
      rescue ScriptError
        flash[:error] = 'Sorry, this message appears to be spam and was not delivered.'
      end
  end

end

在我的 travels_controller 中,我尝试使用相同的方法加载 @question_form,但这似乎不是这样:

 def new
    @offer_season = OfferSeason.find(params[:offer_season_id])
    @travel = @offer_season.travels.find(params[:id])

    @question_form =  @travel.questionforms.new
  end

  def create
    @offer_season = OfferSeason.find(params[:offer_season_id])
    @travel = @offer_season.travels.find(params[:id])


    begin
        @question_form = @travel.questionforms.new(params[:question_form])
        @question_form.request = request
        if @question_form.deliver
          flash.now[:notice] = 'Thank you for your message!'
        else
          render :new
        end
      rescue ScriptError
        flash[:error] = 'Sorry, this message appears to be spam and was not delivered.'
      end
  end
4

0 回答 0