Rails从不同的控制器渲染mail_form gem

时间:2013-01-18 03:01:53

标签: ruby-on-rails-3

来自travels,属于offer,我正在尝试使用mail_form gem生成一个表单 但是我收到这条消息的错误:
* NilClass的未定义方法`model_name':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

0 个答案:

没有答案